1 """Repairs platform for the Workday integration."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from holidays
import list_supported_countries
8 import voluptuous
as vol
10 from homeassistant
import data_entry_flow
21 from .config_flow
import validate_custom_dates
22 from .const
import CONF_PROVINCE, CONF_REMOVE_HOLIDAYS
26 """Handler for an issue fixing flow."""
28 def __init__(self, entry: ConfigEntry, country: str |
None) ->
None:
31 self.
countrycountry: str |
None = country
35 self, user_input: dict[str, str] |
None =
None
37 """Handle the first step of a fix flow."""
43 self, user_input: dict[str, Any] |
None =
None
45 """Handle the country step of a fix flow."""
46 if user_input
is not None:
47 all_countries = list_supported_countries(include_aliases=
False)
48 if not all_countries[user_input[CONF_COUNTRY]]:
50 new_options = {**options, **user_input, CONF_PROVINCE:
None}
51 self.hass.config_entries.async_update_entry(
52 self.
entryentry, options=new_options
54 await self.hass.config_entries.async_reload(self.
entryentry.entry_id)
56 self.
countrycountry = user_input[CONF_COUNTRY]
61 data_schema=vol.Schema(
66 list_supported_countries(include_aliases=
False)
68 mode=SelectSelectorMode.DROPDOWN,
73 description_placeholders={
"title": self.
entryentry.title},
77 self, user_input: dict[str, Any] |
None =
None
79 """Handle the province step of a fix flow."""
80 if user_input
is not None:
81 user_input.setdefault(CONF_PROVINCE,
None)
83 new_options = {**options, **user_input, CONF_COUNTRY: self.
countrycountry}
84 self.hass.config_entries.async_update_entry(self.
entryentry, options=new_options)
85 await self.hass.config_entries.async_reload(self.
entryentry.entry_id)
89 country_provinces = list_supported_countries(include_aliases=
False)[
94 data_schema=vol.Schema(
98 options=country_provinces,
99 mode=SelectSelectorMode.DROPDOWN,
100 translation_key=CONF_PROVINCE,
105 description_placeholders={
106 CONF_COUNTRY: self.
countrycountry,
107 "title": self.
entryentry.title,
113 """Handler for an issue fixing flow."""
116 self, entry: ConfigEntry, country: str |
None, named_holiday: str
120 self.country: str |
None = country
121 self.named_holiday: str = named_holiday
125 self, user_input: dict[str, str] |
None =
None
127 """Handle the first step of a fix flow."""
131 self, user_input: dict[str, Any] |
None =
None
133 """Handle the options step of a fix flow."""
134 errors: dict[str, str] = {}
137 new_options = {**options, **user_input}
139 await self.hass.async_add_executor_job(
140 validate_custom_dates, new_options
143 errors[
"remove_holidays"] =
"remove_holiday_error"
145 self.hass.config_entries.async_update_entry(
146 self.
entryentry, options=new_options
148 await self.hass.config_entries.async_reload(self.
entryentry.entry_id)
151 remove_holidays = self.
entryentry.options[CONF_REMOVE_HOLIDAYS]
152 removed_named_holiday = [
153 value
for value
in remove_holidays
if value != self.named_holiday
163 mode=SelectSelectorMode.DROPDOWN,
168 {CONF_REMOVE_HOLIDAYS: removed_named_holiday},
171 step_id=
"fix_remove_holiday",
172 data_schema=new_schema,
173 description_placeholders={
174 CONF_COUNTRY: self.country
if self.country
else "-",
175 CONF_REMOVE_HOLIDAYS: self.named_holiday,
176 "title": self.
entryentry.title,
185 data: dict[str, Any] |
None,
189 if data
and (entry_id := data.get(
"entry_id")):
190 entry_id = cast(str, entry_id)
191 entry = hass.config_entries.async_get_entry(entry_id)
193 if data
and (holiday := data.get(
"named_holiday"))
and entry:
data_entry_flow.FlowResult async_step_province(self, dict[str, Any]|None user_input=None)
None __init__(self, ConfigEntry entry, str|None country)
data_entry_flow.FlowResult async_step_country(self, dict[str, Any]|None user_input=None)
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
None __init__(self, ConfigEntry entry, str|None country, str named_holiday)
data_entry_flow.FlowResult async_step_fix_remove_holiday(self, dict[str, Any]|None user_input=None)
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
RepairsFlow async_create_fix_flow(HomeAssistant hass, str issue_id, dict[str, Any]|None data)