1 """Config flow to configure WiLight."""
4 from urllib.parse
import urlparse
12 from .const
import DOMAIN
14 CONF_SERIAL_NUMBER =
"serial_number"
15 CONF_MODEL_NAME =
"model_name"
17 WILIGHT_MANUFACTURER =
"All Automacao Ltda"
20 ALLOWED_WILIGHT_COMPONENTS = [
"cover",
"fan",
"light",
"switch"]
24 """Handle a WiLight config flow."""
31 """Initialize the WiLight flow."""
39 self.
_host_host = host
41 self.
_title_title = f
"WL{serial_number}"
49 CONF_HOST: self.
_host_host,
56 self, discovery_info: ssdp.SsdpServiceInfo
57 ) -> ConfigFlowResult:
58 """Handle a discovered WiLight."""
61 not discovery_info.ssdp_location
62 or ssdp.ATTR_UPNP_MANUFACTURER
not in discovery_info.upnp
63 or ssdp.ATTR_UPNP_SERIAL
not in discovery_info.upnp
64 or ssdp.ATTR_UPNP_MODEL_NAME
not in discovery_info.upnp
65 or ssdp.ATTR_UPNP_MODEL_NUMBER
not in discovery_info.upnp
69 if discovery_info.upnp[ssdp.ATTR_UPNP_MANUFACTURER] != WILIGHT_MANUFACTURER:
72 host = urlparse(discovery_info.ssdp_location).hostname
73 serial_number = discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
74 model_name = discovery_info.upnp[ssdp.ATTR_UPNP_MODEL_NAME]
76 if not self.
_wilight_update_wilight_update(host, serial_number, model_name):
81 wilight_component
in ALLOWED_WILIGHT_COMPONENTS
91 self.context[
"title_placeholders"] = {
"name": self.
_title_title}
95 self, user_input: dict[str, Any] |
None =
None
96 ) -> ConfigFlowResult:
97 """Handle user-confirmation of discovered WiLight."""
98 if user_input
is not None:
103 description_placeholders={
104 "name": self.
_title_title,
def _wilight_update(self, host, serial_number, model_name)
ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_ssdp(self, ssdp.SsdpServiceInfo discovery_info)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
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_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)
_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)