1 """Config flow for Cast."""
3 from __future__
import annotations
7 import voluptuous
as vol
20 from .const
import CONF_IGNORE_CEC, CONF_KNOWN_HOSTS, DOMAIN
22 IGNORE_CEC_SCHEMA = vol.Schema(vol.All(cv.ensure_list, [cv.string]))
23 KNOWN_HOSTS_SCHEMA = vol.Schema(vol.All(cv.ensure_list, [cv.string]))
24 WANTED_UUID_SCHEMA = vol.Schema(vol.All(cv.ensure_list, [cv.string]))
28 """Handle a config flow."""
33 """Initialize flow."""
41 config_entry: ConfigEntry,
42 ) -> CastOptionsFlowHandler:
43 """Get the options flow for this handler."""
47 self, user_input: dict[str, Any] |
None =
None
48 ) -> ConfigFlowResult:
49 """Handle a flow initialized by the user."""
53 self, discovery_info: zeroconf.ZeroconfServiceInfo
54 ) -> ConfigFlowResult:
55 """Handle a flow initialized by zeroconf discovery."""
61 self, user_input: dict[str, Any] |
None =
None
62 ) -> ConfigFlowResult:
63 """Confirm the setup."""
67 if user_input
is not None:
69 known_hosts = user_input[CONF_KNOWN_HOSTS]
70 known_hosts = [x.strip()
for x
in known_hosts.split(
",")
if x.strip()]
74 errors[
"base"] =
"invalid_known_hosts"
83 fields[vol.Optional(CONF_KNOWN_HOSTS, default=
"")] = str
86 step_id=
"config", data_schema=vol.Schema(fields), errors=errors
90 self, user_input: dict[str, Any] |
None =
None
91 ) -> ConfigFlowResult:
92 """Confirm the setup."""
96 if user_input
is not None or not onboarding.async_is_onboarded(self.hass):
110 """Handle Google Cast options."""
113 """Initialize Google Cast options flow."""
117 """Manage the Google Cast options."""
121 self, user_input: dict[str, Any] |
None =
None
122 ) -> ConfigFlowResult:
123 """Manage the Google Cast options."""
124 errors: dict[str, str] = {}
126 if user_input
is not None:
128 user_input.get(CONF_KNOWN_HOSTS,
""), KNOWN_HOSTS_SCHEMA
138 self.hass.config_entries.async_update_entry(
143 fields: dict[vol.Marker, type[str]] = {}
144 suggested_value =
_list_to_string(current_config.get(CONF_KNOWN_HOSTS))
148 step_id=
"basic_options",
149 data_schema=vol.Schema(fields),
155 self, user_input: dict[str, Any] |
None =
None
156 ) -> ConfigFlowResult:
157 """Manage the Google Cast options."""
158 errors: dict[str, str] = {}
159 if user_input
is not None:
161 user_input.get(CONF_IGNORE_CEC,
""), IGNORE_CEC_SCHEMA
164 user_input.get(CONF_UUID,
""), WANTED_UUID_SCHEMA
167 if not bad_cec
and not bad_uuid:
170 self.hass.config_entries.async_update_entry(
175 fields: dict[vol.Marker, type[str]] = {}
183 step_id=
"advanced_options",
184 data_schema=vol.Schema(fields),
191 comma_separated_string =
""
193 comma_separated_string =
",".join(items)
194 return comma_separated_string
199 items = [x.strip()
for x
in string.split(
",")
if x.strip()]
201 items = schema(items)
205 return invalid, items
209 fields: dict[vol.Marker, type[str]], key: str, suggested_value: str
211 fields[vol.Optional(key, description={
"suggested_value": suggested_value})] = str
ConfigFlowResult async_step_advanced_options(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_basic_options(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
CastOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_config(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult 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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
bool show_advanced_options(self)
_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)
def _string_to_list(string, schema)
def _list_to_string(items)
None _add_with_suggestion(dict[vol.Marker, type[str]] fields, str key, str suggested_value)