1 """Config flow for Steamist integration."""
3 from __future__
import annotations
6 from typing
import Any, Self
8 from aiosteamist
import Steamist
9 from discovery30303
import Device30303, normalize_mac
10 import voluptuous
as vol
20 from .const
import CONNECTION_EXCEPTIONS, DISCOVER_SCAN_TIMEOUT, DOMAIN
21 from .discovery
import (
22 async_discover_device,
23 async_discover_devices,
24 async_is_steamist_device,
25 async_update_entry_from_discovery,
28 _LOGGER = logging.getLogger(__name__)
32 """Handle a config flow for Steamist."""
36 host: str |
None =
None
39 """Initialize the config flow."""
44 self, discovery_info: dhcp.DhcpServiceInfo
45 ) -> ConfigFlowResult:
46 """Handle discovery via dhcp."""
48 ipaddress=discovery_info.ip,
50 mac=normalize_mac(discovery_info.macaddress),
51 hostname=discovery_info.hostname,
56 self, discovery_info: DiscoveryInfoType
57 ) -> ConfigFlowResult:
58 """Handle integration discovery."""
60 ipaddress=discovery_info[
"ipaddress"],
61 name=discovery_info[
"name"],
62 mac=discovery_info[
"mac"],
63 hostname=discovery_info[
"hostname"],
68 """Handle any discovery."""
70 assert device
is not None
71 mac_address = device.mac
72 mac = dr.format_mac(mac_address)
73 host = device.ipaddress
76 if entry.unique_id == mac
or entry.data[CONF_HOST] == host:
79 and entry.state
is not ConfigEntryState.SETUP_IN_PROGRESS
81 self.hass.config_entries.async_schedule_reload(entry.entry_id)
84 if self.hass.config_entries.flow.async_has_matching_flow(self):
97 """Return True if other_flow is matching this flow."""
98 return other_flow.host == self.
hosthost
101 self, user_input: dict[str, Any] |
None =
None
102 ) -> ConfigFlowResult:
103 """Confirm discovery."""
106 if user_input
is not None:
111 "ipaddress": device.ipaddress,
113 self.context[
"title_placeholders"] = placeholders
115 step_id=
"discovery_confirm", description_placeholders=placeholders
120 """Create a config entry from a device."""
122 data = {CONF_HOST: device.ipaddress, CONF_NAME: device.name}
124 data[CONF_MODEL] = device.hostname.split(
"-", maxsplit=1)[0]
131 self, user_input: dict[str, Any] |
None =
None
132 ) -> ConfigFlowResult:
133 """Handle the step to pick discovered device."""
134 if user_input
is not None:
135 mac = user_input[CONF_DEVICE]
142 entry.data[CONF_HOST]
146 dr.format_mac(device.mac): device
150 mac: f
"{device.name} ({device.ipaddress})"
152 if mac
not in current_unique_ids
and device.ipaddress
not in current_hosts
158 step_id=
"pick_device",
159 data_schema=vol.Schema({vol.Required(CONF_DEVICE): vol.In(devices_name)}),
163 self, user_input: dict[str, Any] |
None =
None
164 ) -> ConfigFlowResult:
165 """Handle the initial step."""
168 if user_input
is not None:
169 if not (host := user_input[CONF_HOST]):
173 await Steamist(host, websession).async_get_status()
174 except CONNECTION_EXCEPTIONS:
175 errors[
"base"] =
"cannot_connect"
177 _LOGGER.exception(
"Unexpected exception")
178 errors[
"base"] =
"unknown"
182 dr.format_mac(discovery.mac), raise_on_progress=
False
190 data_schema=vol.Schema({vol.Optional(CONF_HOST, default=
""): str}),
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
ConfigFlowResult _async_handle_discovery(self)
ConfigFlowResult async_step_discovery_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_pick_device(self, dict[str, Any]|None user_input=None)
bool is_matching(self, Self other_flow)
ConfigFlowResult _async_create_entry_from_device(self, Device30303 device)
ConfigFlowResult async_step_integration_discovery(self, DiscoveryInfoType discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _set_confirm_only(self)
set[str|None] _async_current_ids(self, bool include_ignore=True)
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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
ElkSystem|None async_discover_device(HomeAssistant hass, str host)
list[ElkSystem] async_discover_devices(HomeAssistant hass, int timeout, str|None address=None)
bool async_update_entry_from_discovery(HomeAssistant hass, config_entries.ConfigEntry entry, ElkSystem device)
bool async_is_steamist_device(Device30303 device)
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)