1 """Sensor to indicate whether the current day is a workday."""
3 from __future__
import annotations
5 from functools
import partial
7 from holidays
import HolidayBase, country_holidays
16 from .const
import CONF_PROVINCE, DOMAIN, PLATFORMS
20 hass: HomeAssistant, entry: ConfigEntry, country: str |
None, province: str |
None
22 """Validate country and province."""
31 await hass.async_add_import_executor_job(country_holidays, country)
32 except NotImplementedError
as ex:
39 severity=IssueSeverity.ERROR,
40 translation_key=
"bad_country",
41 translation_placeholders={
"title": entry.title},
42 data={
"entry_id": entry.entry_id,
"country":
None},
53 await hass.async_add_import_executor_job(
54 partial(country_holidays, country, subdiv=province)
56 except NotImplementedError
as ex:
63 severity=IssueSeverity.ERROR,
64 translation_key=
"bad_province",
65 translation_placeholders={
66 CONF_COUNTRY: country,
69 data={
"entry_id": entry.entry_id,
"country": country},
72 f
"Selected province {province} for country {country} is not valid"
77 """Set up Workday from a config entry."""
79 country: str |
None = entry.options.get(CONF_COUNTRY)
80 province: str |
None = entry.options.get(CONF_PROVINCE)
84 if country
and CONF_LANGUAGE
not in entry.options:
89 cls: HolidayBase = await hass.async_add_import_executor_job(
90 partial(country_holidays, country, subdiv=province)
92 default_language = cls.default_language
93 new_options = entry.options.copy()
94 new_options[CONF_LANGUAGE] = default_language
95 hass.config_entries.async_update_entry(entry, options=new_options)
97 entry.async_on_unload(entry.add_update_listener(async_update_listener))
98 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
103 """Update listener for options."""
104 await hass.config_entries.async_reload(entry.entry_id)
108 """Unload Workday config entry."""
110 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
None async_create_issue(HomeAssistant hass, str entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None _async_validate_country_and_province(HomeAssistant hass, ConfigEntry entry, str|None country, str|None province)
None async_update_listener(HomeAssistant hass, ConfigEntry entry)
Generator[None] async_pause_setup(core.HomeAssistant hass, SetupPhases phase)