mirror of
https://github.com/home-assistant/core.git
synced 2026-05-23 09:15:45 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 65251700a8 | |||
| d119057289 | |||
| 50a8378148 | |||
| 4f0528fa57 | |||
| 634d90adbe |
@@ -69,3 +69,20 @@ async def async_unload_entry(hass: HomeAssistant, entry: WorkdayConfigEntry) ->
|
||||
"""Unload Workday config entry."""
|
||||
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, entry: WorkdayConfigEntry) -> bool:
|
||||
"""Migrate old config entry."""
|
||||
|
||||
# This means the user has downgraded from a future version
|
||||
if entry.version > 1:
|
||||
return False
|
||||
|
||||
if entry.version == 1 and entry.minor_version == 1:
|
||||
# By keeping name in the data, it's enough to bump the minor version
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
minor_version=2,
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@@ -7,7 +7,6 @@ from holidays import HolidayBase
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, SupportsResponse
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
@@ -31,7 +30,6 @@ async def async_setup_entry(
|
||||
"""Set up the Workday sensor."""
|
||||
days_offset: int = int(entry.options[CONF_OFFSET])
|
||||
excludes: list[str] = entry.options[CONF_EXCLUDES]
|
||||
sensor_name: str = entry.options[CONF_NAME]
|
||||
workdays: list[str] = entry.options[CONF_WORKDAYS]
|
||||
obj_holidays = entry.runtime_data
|
||||
|
||||
@@ -51,7 +49,7 @@ async def async_setup_entry(
|
||||
workdays,
|
||||
excludes,
|
||||
days_offset,
|
||||
sensor_name,
|
||||
entry.title,
|
||||
entry.entry_id,
|
||||
)
|
||||
],
|
||||
|
||||
@@ -5,7 +5,6 @@ from datetime import date, datetime, timedelta
|
||||
from holidays import HolidayBase
|
||||
|
||||
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
@@ -23,7 +22,6 @@ async def async_setup_entry(
|
||||
"""Set up the Holiday Calendar config entry."""
|
||||
days_offset: int = int(entry.options[CONF_OFFSET])
|
||||
excludes: list[str] = entry.options[CONF_EXCLUDES]
|
||||
sensor_name: str = entry.options[CONF_NAME]
|
||||
workdays: list[str] = entry.options[CONF_WORKDAYS]
|
||||
obj_holidays = entry.runtime_data
|
||||
|
||||
@@ -34,7 +32,7 @@ async def async_setup_entry(
|
||||
workdays,
|
||||
excludes,
|
||||
days_offset,
|
||||
sensor_name,
|
||||
entry.title,
|
||||
entry.entry_id,
|
||||
)
|
||||
],
|
||||
|
||||
@@ -12,7 +12,7 @@ from homeassistant.config_entries import (
|
||||
ConfigFlowResult,
|
||||
OptionsFlowWithReload,
|
||||
)
|
||||
from homeassistant.const import CONF_COUNTRY, CONF_LANGUAGE, CONF_NAME
|
||||
from homeassistant.const import CONF_COUNTRY, CONF_LANGUAGE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import AbortFlow
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -28,7 +28,6 @@ from homeassistant.helpers.selector import (
|
||||
SelectSelector,
|
||||
SelectSelectorConfig,
|
||||
SelectSelectorMode,
|
||||
TextSelector,
|
||||
)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
@@ -213,6 +212,7 @@ class WorkdayConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Workday integration."""
|
||||
|
||||
VERSION = 1
|
||||
MINOR_VERSION = 2
|
||||
|
||||
data: dict[str, Any] = {}
|
||||
|
||||
@@ -241,9 +241,6 @@ class WorkdayConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
# Name field is no longer allowed in config flow schemas
|
||||
# pylint: disable-next=home-assistant-config-flow-name-field
|
||||
vol.Required(CONF_NAME, default=DEFAULT_NAME): TextSelector(),
|
||||
vol.Optional(CONF_COUNTRY): CountrySelector(
|
||||
CountrySelectorConfig(
|
||||
countries=list(supported_countries),
|
||||
@@ -292,8 +289,14 @@ class WorkdayConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
LOGGER.debug("Errors have occurred %s", errors)
|
||||
if not errors:
|
||||
LOGGER.debug("No duplicate, no errors, creating entry")
|
||||
|
||||
name = DEFAULT_NAME
|
||||
if (country := combined_input.get(CONF_COUNTRY)) is not None:
|
||||
name += f" {country}"
|
||||
if (province := combined_input.get(CONF_PROVINCE)) is not None:
|
||||
name += f" {province}"
|
||||
return self.async_create_entry(
|
||||
title=combined_input[CONF_NAME],
|
||||
title=name,
|
||||
data={},
|
||||
options=combined_input,
|
||||
)
|
||||
@@ -309,7 +312,6 @@ class WorkdayConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
data_schema=new_schema,
|
||||
errors=errors,
|
||||
description_placeholders={
|
||||
"name": self.data[CONF_NAME],
|
||||
"country": self.data.get(CONF_COUNTRY, "-"),
|
||||
},
|
||||
)
|
||||
@@ -376,7 +378,7 @@ class WorkdayOptionsFlowHandler(OptionsFlowWithReload):
|
||||
data_schema=new_schema,
|
||||
errors=errors,
|
||||
description_placeholders={
|
||||
"name": options[CONF_NAME],
|
||||
"name": self.config_entry.title,
|
||||
"country": options.get(CONF_COUNTRY, "-"),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"remove_holidays": "Remove holidays as YYYY-MM-DD, as range using `,` as separator or by using partial of name",
|
||||
"workdays": "Select which weekdays to include as possible workdays."
|
||||
},
|
||||
"description": "Set additional options for {name} configured for country {country}"
|
||||
"description": "Set additional options for country {country}"
|
||||
},
|
||||
"user": {
|
||||
"data": {
|
||||
|
||||
@@ -23,7 +23,13 @@ async def init_integration(
|
||||
entry_id: str = "1",
|
||||
source: str = SOURCE_USER,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Scrape integration in Home Assistant."""
|
||||
"""Set up the Workday integration in Home Assistant."""
|
||||
|
||||
name = DEFAULT_NAME
|
||||
if config.get("country"):
|
||||
name += f" {config['country']}"
|
||||
if config.get("province"):
|
||||
name += f" {config['province']}"
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@@ -31,6 +37,8 @@ async def init_integration(
|
||||
data={},
|
||||
options=config,
|
||||
entry_id=entry_id,
|
||||
title=name,
|
||||
minor_version=2,
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
@@ -42,7 +50,6 @@ async def init_integration(
|
||||
|
||||
|
||||
TEST_CONFIG_NO_COUNTRY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
"workdays": DEFAULT_WORKDAYS,
|
||||
@@ -50,15 +57,13 @@ TEST_CONFIG_NO_COUNTRY = {
|
||||
"remove_holidays": [],
|
||||
}
|
||||
TEST_CONFIG_NO_COUNTRY_ADD_HOLIDAY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
"workdays": DEFAULT_WORKDAYS,
|
||||
"add_holidays": ["2020-02-24"],
|
||||
"add_holidays": ["2020-02-24", "2022-04-15"],
|
||||
"remove_holidays": [],
|
||||
}
|
||||
TEST_CONFIG_WITH_PROVINCE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -69,7 +74,6 @@ TEST_CONFIG_WITH_PROVINCE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_NO_LANGUAGE_CONFIGURED = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -79,7 +83,6 @@ TEST_CONFIG_NO_LANGUAGE_CONFIGURED = {
|
||||
"remove_holidays": [],
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_COUNTRY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "ZZ",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -89,7 +92,6 @@ TEST_CONFIG_INCORRECT_COUNTRY = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_PROVINCE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "ZZ",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -100,7 +102,6 @@ TEST_CONFIG_INCORRECT_PROVINCE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_NO_PROVINCE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -110,7 +111,6 @@ TEST_CONFIG_NO_PROVINCE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_WITH_STATE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"province": "CA",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -121,7 +121,6 @@ TEST_CONFIG_WITH_STATE = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_NO_STATE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -131,7 +130,6 @@ TEST_CONFIG_NO_STATE = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_INCLUDE_HOLIDAY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": ["sat", "sun"],
|
||||
@@ -142,7 +140,6 @@ TEST_CONFIG_INCLUDE_HOLIDAY = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_EXAMPLE_1 = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"excludes": ["sat", "sun"],
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -152,7 +149,6 @@ TEST_CONFIG_EXAMPLE_1 = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_EXAMPLE_2 = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -163,7 +159,6 @@ TEST_CONFIG_EXAMPLE_2 = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_REMOVE_HOLIDAY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -173,7 +168,6 @@ TEST_CONFIG_REMOVE_HOLIDAY = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_REMOVE_NAMED = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -183,7 +177,6 @@ TEST_CONFIG_REMOVE_NAMED = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_REMOVE_DATE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "US",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
@@ -193,7 +186,6 @@ TEST_CONFIG_REMOVE_DATE = {
|
||||
"language": "en_US",
|
||||
}
|
||||
TEST_CONFIG_TOMORROW = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": 1,
|
||||
@@ -203,7 +195,6 @@ TEST_CONFIG_TOMORROW = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_DAY_AFTER_TOMORROW = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": 2,
|
||||
@@ -213,7 +204,6 @@ TEST_CONFIG_DAY_AFTER_TOMORROW = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_YESTERDAY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
"days_offset": -1,
|
||||
@@ -223,7 +213,6 @@ TEST_CONFIG_YESTERDAY = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_ADD_REMOVE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -234,7 +223,6 @@ TEST_CONFIG_INCORRECT_ADD_REMOVE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_ADD_DATE_RANGE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -245,7 +233,6 @@ TEST_CONFIG_INCORRECT_ADD_DATE_RANGE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -256,7 +243,6 @@ TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_ADD_DATE_RANGE_LEN = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -267,7 +253,6 @@ TEST_CONFIG_INCORRECT_ADD_DATE_RANGE_LEN = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE_LEN = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -278,7 +263,6 @@ TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE_LEN = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_CONFIG_ADD_REMOVE_DATE_RANGE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -289,7 +273,6 @@ TEST_CONFIG_ADD_REMOVE_DATE_RANGE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_LANGUAGE_CHANGE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -300,7 +283,6 @@ TEST_LANGUAGE_CHANGE = {
|
||||
"language": "en",
|
||||
}
|
||||
TEST_LANGUAGE_NO_CHANGE = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "DE",
|
||||
"province": "BW",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -311,7 +293,6 @@ TEST_LANGUAGE_NO_CHANGE = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_NO_OPTIONAL_CATEGORY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "CH",
|
||||
"province": "FR",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
@@ -322,7 +303,6 @@ TEST_NO_OPTIONAL_CATEGORY = {
|
||||
"language": "de",
|
||||
}
|
||||
TEST_OPTIONAL_CATEGORY = {
|
||||
"name": DEFAULT_NAME,
|
||||
"country": "CH",
|
||||
"province": "FR",
|
||||
"excludes": DEFAULT_EXCLUDES,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
'translation_placeholders': dict({
|
||||
'country': 'DE',
|
||||
'remove_holidays': '2024-08-15',
|
||||
'title': 'Mock Title',
|
||||
'title': 'Workday Sensor DE BW',
|
||||
}),
|
||||
}),
|
||||
tuple(
|
||||
@@ -52,7 +52,7 @@
|
||||
'translation_placeholders': dict({
|
||||
'country': 'DE',
|
||||
'remove_holidays': '2025-08-15',
|
||||
'title': 'Mock Title',
|
||||
'title': 'Workday Sensor DE BW',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
}),
|
||||
'domain': 'workday',
|
||||
'entry_id': '1',
|
||||
'minor_version': 1,
|
||||
'minor_version': 2,
|
||||
'options': dict({
|
||||
'add_holidays': list([
|
||||
'2022-12-01',
|
||||
@@ -23,7 +23,6 @@
|
||||
'holiday',
|
||||
]),
|
||||
'language': 'de',
|
||||
'name': 'Workday Sensor',
|
||||
'province': 'BW',
|
||||
'remove_holidays': list([
|
||||
'2022-12-04',
|
||||
@@ -42,7 +41,7 @@
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Mock Title',
|
||||
'title': 'Workday Sensor DE BW',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
|
||||
@@ -18,7 +18,7 @@ from homeassistant.components.workday.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util import dt as dt_util, slugify
|
||||
from homeassistant.util.dt import UTC
|
||||
|
||||
from . import (
|
||||
@@ -69,6 +69,7 @@ from tests.common import async_fire_time_changed
|
||||
(TEST_CONFIG_DAY_AFTER_TOMORROW, "off", "off"),
|
||||
(TEST_CONFIG_YESTERDAY, "on", "off"), # Friday was good Friday
|
||||
(TEST_CONFIG_NO_LANGUAGE_CONFIGURED, "off", "off"),
|
||||
(TEST_CONFIG_NO_COUNTRY_ADD_HOLIDAY, "off", "off"),
|
||||
],
|
||||
)
|
||||
async def test_setup(
|
||||
@@ -84,11 +85,18 @@ async def test_setup(
|
||||
freezer.move_to(datetime(2022, 4, 15, 0, tzinfo=timezone(timedelta(hours=1))))
|
||||
await init_integration(hass, config)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
name = "Workday Sensor"
|
||||
if config.get("country"):
|
||||
name += f" {config['country']}"
|
||||
if config.get("province"):
|
||||
name += f" {config['province']}"
|
||||
slug_name = slugify(name)
|
||||
|
||||
state = hass.states.get(f"binary_sensor.{slug_name}")
|
||||
assert state is not None
|
||||
assert state.state == expected_state
|
||||
assert state.attributes == {
|
||||
"friendly_name": "Workday Sensor",
|
||||
"friendly_name": name,
|
||||
"workdays": config["workdays"],
|
||||
"excludes": config["excludes"],
|
||||
"days_offset": config["days_offset"],
|
||||
@@ -97,7 +105,7 @@ async def test_setup(
|
||||
freezer.tick(timedelta(days=1)) # Saturday
|
||||
async_fire_time_changed(hass)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get(f"binary_sensor.{slug_name}")
|
||||
assert state is not None
|
||||
assert state.state == expected_state_weekend
|
||||
|
||||
@@ -129,28 +137,20 @@ async def test_setup_with_working_holiday(
|
||||
freezer.move_to(datetime(2017, 1, 6, 12, tzinfo=UTC)) # Friday
|
||||
await init_integration(hass, TEST_CONFIG_INCLUDE_HOLIDAY)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config",
|
||||
[
|
||||
TEST_CONFIG_EXAMPLE_2,
|
||||
TEST_CONFIG_NO_COUNTRY_ADD_HOLIDAY,
|
||||
],
|
||||
)
|
||||
async def test_setup_add_holiday(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test setup from various configs."""
|
||||
freezer.move_to(datetime(2020, 2, 24, 12, tzinfo=UTC)) # Monday
|
||||
await init_integration(hass, TEST_CONFIG_EXAMPLE_2)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
@@ -217,7 +217,7 @@ async def test_setup_remove_holiday(
|
||||
freezer.move_to(datetime(2020, 12, 25, 12, tzinfo=UTC)) # Friday
|
||||
await init_integration(hass, TEST_CONFIG_REMOVE_HOLIDAY)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
@@ -230,7 +230,7 @@ async def test_setup_remove_holiday_named(
|
||||
freezer.move_to(datetime(2020, 12, 25, 12, tzinfo=UTC)) # Friday
|
||||
await init_integration(hass, TEST_CONFIG_REMOVE_NAMED)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
@@ -243,7 +243,7 @@ async def test_setup_day_after_tomorrow(
|
||||
freezer.move_to(datetime(2022, 5, 27, 12, tzinfo=UTC)) # Friday
|
||||
await init_integration(hass, TEST_CONFIG_DAY_AFTER_TOMORROW)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
@@ -342,7 +342,7 @@ async def test_setup_date_range(
|
||||
) # Boxing Day should be working day
|
||||
await init_integration(hass, TEST_CONFIG_ADD_REMOVE_DATE_RANGE)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state.state == "on"
|
||||
|
||||
|
||||
@@ -355,43 +355,43 @@ async def test_check_date_service(
|
||||
freezer.move_to(datetime(2017, 1, 6, 12, tzinfo=UTC)) # Friday
|
||||
await init_integration(hass, TEST_CONFIG_WITH_PROVINCE)
|
||||
|
||||
hass.states.get("binary_sensor.workday_sensor")
|
||||
hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor",
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 25), # Christmas Day
|
||||
},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert response == {"binary_sensor.workday_sensor": {"workday": False}}
|
||||
assert response == {"binary_sensor.workday_sensor_de_bw": {"workday": False}}
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor",
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 23), # Normal Friday
|
||||
},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert response == {"binary_sensor.workday_sensor": {"workday": True}}
|
||||
assert response == {"binary_sensor.workday_sensor_de_bw": {"workday": True}}
|
||||
|
||||
response = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CHECK_DATE,
|
||||
{
|
||||
"entity_id": "binary_sensor.workday_sensor",
|
||||
"entity_id": "binary_sensor.workday_sensor_de_bw",
|
||||
"check_date": date(2022, 12, 17), # Saturday (no workday)
|
||||
},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert response == {"binary_sensor.workday_sensor": {"workday": False}}
|
||||
assert response == {"binary_sensor.workday_sensor_de_bw": {"workday": False}}
|
||||
|
||||
|
||||
async def test_language_difference_english_language(
|
||||
@@ -427,7 +427,7 @@ async def test_optional_category(
|
||||
freezer.move_to(datetime(2024, 1, 2, 12, tzinfo=UTC)) # Tuesday
|
||||
await init_integration(hass, config)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_ch_fr")
|
||||
assert state is not None
|
||||
assert state.state == end_state
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ async def test_holiday_calendar_entity(
|
||||
CALENDAR_DOMAIN,
|
||||
SERVICE_GET_EVENTS,
|
||||
{
|
||||
ATTR_ENTITY_ID: "calendar.workday_sensor_calendar",
|
||||
ATTR_ENTITY_ID: "calendar.workday_sensor_de_bw_calendar",
|
||||
EVENT_START_DATETIME: dt_util.now(),
|
||||
EVENT_END_DATETIME: dt_util.now() + timedelta(days=10, hours=1),
|
||||
},
|
||||
@@ -52,15 +52,15 @@ async def test_holiday_calendar_entity(
|
||||
assert {
|
||||
ATTR_END: "2023-01-02",
|
||||
ATTR_START: "2023-01-01",
|
||||
EVENT_SUMMARY: "Workday Sensor",
|
||||
} not in response["calendar.workday_sensor_calendar"]["events"]
|
||||
EVENT_SUMMARY: "Workday Sensor DE BW",
|
||||
} not in response["calendar.workday_sensor_de_bw_calendar"]["events"]
|
||||
assert {
|
||||
ATTR_END: "2023-01-04",
|
||||
ATTR_START: "2023-01-03",
|
||||
EVENT_SUMMARY: "Workday Sensor",
|
||||
} in response["calendar.workday_sensor_calendar"]["events"]
|
||||
EVENT_SUMMARY: "Workday Sensor DE BW",
|
||||
} in response["calendar.workday_sensor_de_bw_calendar"]["events"]
|
||||
|
||||
state = hass.states.get("calendar.workday_sensor_calendar")
|
||||
state = hass.states.get("calendar.workday_sensor_de_bw_calendar")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
@@ -71,11 +71,11 @@ async def test_holiday_calendar_entity(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Binary sensor added to ensure same state for both entities
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
state = hass.states.get("calendar.workday_sensor_calendar")
|
||||
state = hass.states.get("calendar.workday_sensor_de_bw_calendar")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
@@ -83,10 +83,10 @@ async def test_holiday_calendar_entity(
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
state = hass.states.get("calendar.workday_sensor_calendar")
|
||||
state = hass.states.get("calendar.workday_sensor_de_bw_calendar")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
@@ -20,7 +20,7 @@ from homeassistant.components.workday.const import (
|
||||
DEFAULT_WORKDAYS,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_COUNTRY, CONF_LANGUAGE, CONF_NAME
|
||||
from homeassistant.const import CONF_COUNTRY, CONF_LANGUAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.util.dt import UTC
|
||||
@@ -40,7 +40,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
@@ -59,9 +58,8 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor DE"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -84,7 +82,6 @@ async def test_form_province_no_alias(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "US",
|
||||
},
|
||||
)
|
||||
@@ -102,9 +99,8 @@ async def test_form_province_no_alias(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor US"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "US",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"language": "en_US",
|
||||
@@ -126,9 +122,7 @@ async def test_form_no_country(hass: HomeAssistant) -> None:
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
},
|
||||
{},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
@@ -146,7 +140,6 @@ async def test_form_no_country(hass: HomeAssistant) -> None:
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
||||
@@ -167,7 +160,6 @@ async def test_form_no_subdivision(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "SE",
|
||||
},
|
||||
)
|
||||
@@ -185,9 +177,8 @@ async def test_form_no_subdivision(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor SE"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "SE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -205,7 +196,6 @@ async def test_options_form(hass: HomeAssistant) -> None:
|
||||
entry = await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -233,7 +223,6 @@ async def test_options_form(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -257,7 +246,6 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
@@ -305,9 +293,8 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor DE"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -325,7 +312,6 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None:
|
||||
entry = await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -383,7 +369,6 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -402,7 +387,6 @@ async def test_options_form_abort_duplicate(hass: HomeAssistant) -> None:
|
||||
await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor",
|
||||
"country": "CH",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -417,7 +401,6 @@ async def test_options_form_abort_duplicate(hass: HomeAssistant) -> None:
|
||||
entry2 = await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor2",
|
||||
"country": "CH",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -461,7 +444,6 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
@@ -509,9 +491,8 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor DE"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -529,7 +510,6 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None:
|
||||
entry = await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -587,7 +567,6 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -620,7 +599,6 @@ async def test_language(
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "DE",
|
||||
},
|
||||
)
|
||||
@@ -639,9 +617,8 @@ async def test_language(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor DE"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -651,7 +628,7 @@ async def test_language(
|
||||
"language": language,
|
||||
}
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
@@ -667,7 +644,6 @@ async def test_form_with_categories(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "CH",
|
||||
},
|
||||
)
|
||||
@@ -687,9 +663,8 @@ async def test_form_with_categories(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor CH"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "CH",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -712,7 +687,6 @@ async def test_form_with_categories_can_remove_day(hass: HomeAssistant) -> None:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_NAME: "Workday Sensor",
|
||||
CONF_COUNTRY: "CH",
|
||||
},
|
||||
)
|
||||
@@ -733,9 +707,8 @@ async def test_form_with_categories_can_remove_day(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Workday Sensor"
|
||||
assert result3["title"] == "Workday Sensor CH FR"
|
||||
assert result3["options"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "CH",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -754,7 +727,6 @@ async def test_options_form_removes_subdiv(hass: HomeAssistant) -> None:
|
||||
entry = await init_integration(
|
||||
hass,
|
||||
{
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
@@ -782,7 +754,6 @@ async def test_options_form_removes_subdiv(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
"name": "Workday Sensor",
|
||||
"country": "DE",
|
||||
"excludes": ["sat", "sun", "holiday"],
|
||||
"days_offset": 0,
|
||||
|
||||
@@ -5,24 +5,31 @@ from datetime import datetime
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from holidays.utils import country_holidays
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.components.workday.const import (
|
||||
DEFAULT_OFFSET,
|
||||
DEFAULT_WORKDAYS,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.dt import UTC
|
||||
|
||||
from . import TEST_CONFIG_EXAMPLE_1, TEST_CONFIG_WITH_PROVINCE, init_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_load_unload_entry(hass: HomeAssistant) -> None:
|
||||
"""Test load and unload entry."""
|
||||
entry = await init_integration(hass, TEST_CONFIG_EXAMPLE_1)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state
|
||||
|
||||
await hass.config_entries.async_remove(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert not state
|
||||
|
||||
|
||||
@@ -36,7 +43,7 @@ async def test_update_options(
|
||||
entry = await init_integration(hass, TEST_CONFIG_WITH_PROVINCE)
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert entry.update_listeners is not None
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state.state == "on"
|
||||
|
||||
new_options = TEST_CONFIG_WITH_PROVINCE.copy()
|
||||
@@ -48,7 +55,7 @@ async def test_update_options(
|
||||
|
||||
entry_check = hass.config_entries.async_get_entry("1")
|
||||
assert entry_check.state is ConfigEntryState.LOADED
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_bw")
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
@@ -61,3 +68,37 @@ async def test_workday_subdiv_aliases() -> None:
|
||||
)
|
||||
subdiv_aliases = country.get_subdivision_aliases()
|
||||
assert subdiv_aliases["6AE"] == ["Alsace"]
|
||||
|
||||
|
||||
async def test_migrate_minor_version_1_to_2(hass: HomeAssistant) -> None:
|
||||
"""Test migrates to version 1.2."""
|
||||
config = {
|
||||
"name": "Test sensor",
|
||||
"country": "US",
|
||||
"excludes": ["sat", "sun"],
|
||||
"days_offset": DEFAULT_OFFSET,
|
||||
"workdays": DEFAULT_WORKDAYS,
|
||||
"add_holidays": [],
|
||||
"remove_holidays": [],
|
||||
"language": "en_US",
|
||||
}
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
source=SOURCE_USER,
|
||||
data={},
|
||||
options=config,
|
||||
entry_id="1",
|
||||
title="Test sensor",
|
||||
minor_version=1,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.test_sensor")
|
||||
assert state
|
||||
|
||||
assert config_entry.version == 1
|
||||
assert config_entry.minor_version == 2
|
||||
assert config_entry.options == config
|
||||
|
||||
@@ -30,7 +30,7 @@ async def test_bad_country(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_INCORRECT_COUNTRY)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert not state
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
@@ -60,7 +60,7 @@ async def test_bad_country(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -83,7 +83,7 @@ async def test_bad_country_none(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_INCORRECT_COUNTRY)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert not state
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
@@ -113,7 +113,7 @@ async def test_bad_country_none(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -136,7 +136,7 @@ async def test_bad_country_no_province(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_INCORRECT_COUNTRY)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert not state
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
@@ -164,7 +164,7 @@ async def test_bad_country_no_province(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_zz")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -187,7 +187,7 @@ async def test_bad_province(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_INCORRECT_PROVINCE)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_zz")
|
||||
assert not state
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
@@ -218,7 +218,7 @@ async def test_bad_province(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_zz")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -241,7 +241,7 @@ async def test_bad_province_none(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_INCORRECT_PROVINCE)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_zz")
|
||||
assert not state
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
@@ -272,7 +272,7 @@ async def test_bad_province_none(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_de_zz")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -296,7 +296,7 @@ async def test_bad_named_holiday(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_REMOVE_NAMED)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state
|
||||
|
||||
issues = issue_registry.issues.keys()
|
||||
@@ -345,7 +345,7 @@ async def test_bad_named_holiday(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
@@ -369,7 +369,7 @@ async def test_bad_date_holiday(
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
entry = await init_integration(hass, TEST_CONFIG_REMOVE_DATE)
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state
|
||||
|
||||
issues = issue_registry.issues.keys()
|
||||
@@ -408,7 +408,7 @@ async def test_bad_date_holiday(
|
||||
assert data["type"] == "create_entry"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.workday_sensor")
|
||||
state = hass.states.get("binary_sensor.workday_sensor_us")
|
||||
assert state
|
||||
|
||||
await ws_client.send_json({"id": 2, "type": "repairs/list_issues"})
|
||||
|
||||
Reference in New Issue
Block a user