1 """Config flow to configure the Elgato Light integration."""
3 from __future__
import annotations
7 from elgato
import Elgato, ElgatoError
8 import voluptuous
as vol
16 from .const
import DOMAIN
20 """Handle a Elgato Light config flow."""
27 mac: str |
None =
None
30 self, user_input: dict[str, Any] |
None =
None
31 ) -> ConfigFlowResult:
32 """Handle a flow initiated by the user."""
33 if user_input
is None:
34 return self._async_show_setup_form()
36 self.
hosthost = user_input[CONF_HOST]
37 self.
portport = user_input[CONF_PORT]
40 await self._get_elgato_serial_number(raise_on_progress=
False)
42 return self._async_show_setup_form({
"base":
"cannot_connect"})
44 return self._async_create_entry()
47 self, discovery_info: zeroconf.ZeroconfServiceInfo
48 ) -> ConfigFlowResult:
49 """Handle zeroconf discovery."""
50 self.
hosthost = discovery_info.host
51 self.
macmac = discovery_info.properties.get(
"id")
52 self.
portport = discovery_info.port
or 9123
55 await self._get_elgato_serial_number()
59 if not onboarding.async_is_onboarded(self.hass):
60 return self._async_create_entry()
64 step_id=
"zeroconf_confirm",
65 description_placeholders={
"serial_number": self.
serial_numberserial_number},
68 async
def async_step_zeroconf_confirm(
69 self, _: dict[str, Any] |
None =
None
70 ) -> ConfigFlowResult:
71 """Handle a flow initiated by zeroconf."""
72 return self._async_create_entry()
75 def _async_show_setup_form(
76 self, errors: dict[str, str] |
None =
None
77 ) -> ConfigFlowResult:
78 """Show the setup form to the user."""
81 data_schema=vol.Schema(
83 vol.Required(CONF_HOST): str,
84 vol.Optional(CONF_PORT, default=9123): int,
91 def _async_create_entry(self) -> ConfigFlowResult:
95 CONF_HOST: self.
hosthost,
96 CONF_PORT: self.
portport,
97 CONF_MAC: self.
macmac,
101 async
def _get_elgato_serial_number(self, raise_on_progress: bool =
True) ->
None:
102 """Get device information from an Elgato Light device."""
109 info = await elgato.info()
113 info.serial_number, raise_on_progress=raise_on_progress
116 updates={CONF_HOST: self.
hosthost, CONF_PORT: self.
portport, CONF_MAC: self.
macmac}
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
None _set_confirm_only(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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_step_zeroconf(self, ZeroconfServiceInfo discovery_info)
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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)