1 """Config flow for SiteSage Emonitor integration."""
6 from aioemonitor
import Emonitor
8 import voluptuous
as vol
17 from .
import name_short_mac
18 from .const
import DOMAIN
20 _LOGGER = logging.getLogger(__name__)
24 """Validate the user input allows us to connect."""
25 session = aiohttp_client.async_get_clientsession(hass)
26 emonitor = Emonitor(host, session)
27 status = await emonitor.async_get_status()
28 mac_address = status.network.mac_address
29 return {
"title":
name_short_mac(mac_address[-6:]),
"mac_address": mac_address}
33 """Handle a config flow for SiteSage Emonitor."""
37 discovered_info: dict[str, str]
40 """Initialize Emonitor ConfigFlow."""
44 self, user_input: dict[str, Any] |
None =
None
45 ) -> ConfigFlowResult:
46 """Handle the initial step."""
48 if user_input
is not None:
51 except aiohttp.ClientError:
52 errors[CONF_HOST] =
"cannot_connect"
54 _LOGGER.exception(
"Unexpected exception")
55 errors[
"base"] =
"unknown"
58 format_mac(info[
"mac_address"]), raise_on_progress=
False
65 data_schema=vol.Schema(
66 {vol.Required(
"host", default=self.
discovered_ipdiscovered_ip): str}
72 self, discovery_info: dhcp.DhcpServiceInfo
73 ) -> ConfigFlowResult:
74 """Handle dhcp discovery."""
79 self.context[
"title_placeholders"] = {
"name": name}
84 except Exception
as ex:
86 "Unable to fetch status, falling back to manual entry", exc_info=ex
92 self, user_input: dict[str, Any] |
None =
None
93 ) -> ConfigFlowResult:
94 """Attempt to confirm."""
96 if user_input
is not None:
103 self.context[
"title_placeholders"] = {
"name": self.
discovered_infodiscovered_info[
"title"]}
106 description_placeholders={
114 """Short version of the mac."""
115 return "".join(mac.split(
":")[3:]).upper()
ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
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_step_user(self, dict[str, Any]|None user_input=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)
def fetch_mac_and_title(HomeAssistant hass, host)
def name_short_mac(short_mac)