1 """Config flow for Philips TV integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from haphilipsjs
import ConnectionFailure, PairingFailure, PhilipsTV
10 import voluptuous
as vol
29 SchemaOptionsFlowHandler,
33 from .const
import CONF_ALLOW_NOTIFY, CONF_SYSTEM, CONST_APP_ID, CONST_APP_NAME, DOMAIN
35 USER_SCHEMA = vol.Schema(
47 OPTIONS_SCHEMA = vol.Schema(
49 vol.Optional(CONF_ALLOW_NOTIFY, default=
False): selector.BooleanSelector(),
58 hass: HomeAssistant, host: str, api_version: int
60 """Validate the user input allows us to connect."""
61 hub = PhilipsTV(host, api_version)
64 await hub.setTransport(hub.secured_transport)
67 raise ConnectionFailure(
"System data is empty")
73 """Handle a config flow for Philips TV."""
78 """Initialize flow."""
80 self.
_current_current: dict[str, Any] = {}
81 self.
_hub_hub: PhilipsTV |
None =
None
85 system = self.
_current_current[CONF_SYSTEM]
92 title=f
"{system['name']} ({system['serialnumber']})",
97 self, user_input: dict[str, Any] |
None =
None
98 ) -> ConfigFlowResult:
99 """Attempt to pair with device."""
102 errors: dict[str, str] = {}
105 vol.Required(CONF_PIN): str,
118 except PairingFailure
as exc:
121 reason=
"pairing_failure",
122 description_placeholders={
"error_id": exc.data.get(
"error_id")},
125 step_id=
"pair", data_schema=schema, errors=errors
129 username, password = await self.
_hub_hub.pairGrant(
132 except PairingFailure
as exc:
134 if exc.data.get(
"error_id") ==
"INVALID_PIN":
135 errors[CONF_PIN] =
"invalid_pin"
137 step_id=
"pair", data_schema=schema, errors=errors
141 reason=
"pairing_failure",
142 description_placeholders={
"error_id": exc.data.get(
"error_id")},
145 self.
_current_current[CONF_USERNAME] = username
146 self.
_current_current[CONF_PASSWORD] = password
150 self, entry_data: Mapping[str, Any]
151 ) -> ConfigFlowResult:
152 """Handle configuration by re-auth."""
153 self.
_current_current[CONF_HOST] = entry_data[CONF_HOST]
154 self.
_current_current[CONF_API_VERSION] = entry_data[CONF_API_VERSION]
158 self, user_input: dict[str, Any] |
None =
None
159 ) -> ConfigFlowResult:
160 """Handle the initial step."""
166 self.hass, user_input[CONF_HOST], user_input[CONF_API_VERSION]
168 except ConnectionFailure
as exc:
170 errors[
"base"] =
"cannot_connect"
172 LOGGER.exception(
"Unexpected exception")
173 errors[
"base"] =
"unknown"
175 if serialnumber := hub.system.get(
"serialnumber"):
180 self.
_current_current[CONF_SYSTEM] = hub.system
181 self.
_current_current[CONF_API_VERSION] = hub.api_version
184 if hub.pairing_type ==
"digest_auth_pairing":
194 config_entry: ConfigEntry,
195 ) -> SchemaOptionsFlowHandler:
196 """Get the options flow for this handler."""
SchemaOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _async_create_current(self)
ConfigFlowResult async_step_pair(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
PhilipsTV _validate_input(HomeAssistant hass, str host, int api_version)