1 """Config flow for Airgradient."""
5 from airgradient
import (
11 from awesomeversion
import AwesomeVersion
12 import voluptuous
as vol
19 from .const
import DOMAIN
21 MIN_VERSION = AwesomeVersion(
"3.1.1")
25 """AirGradient config flow."""
28 """Initialize the config flow."""
29 self.data: dict[str, Any] = {}
30 self.
clientclient: AirGradientClient |
None =
None
33 """Set configuration source to local if it hasn't been set yet."""
35 config = await self.
clientclient.get_config()
36 if config.configuration_control
is ConfigurationControl.NOT_INITIALIZED:
37 await self.
clientclient.set_configuration_control(ConfigurationControl.LOCAL)
40 self, discovery_info: zeroconf.ZeroconfServiceInfo
41 ) -> ConfigFlowResult:
42 """Handle zeroconf discovery."""
43 self.data[CONF_HOST] = host = discovery_info.host
44 self.data[CONF_MODEL] = discovery_info.properties[
"model"]
49 if AwesomeVersion(discovery_info.properties[
"fw_ver"]) < MIN_VERSION:
53 self.
clientclient = AirGradientClient(host, session=session)
54 await self.
clientclient.get_current_measures()
56 self.context[
"title_placeholders"] = {
57 "model": self.data[CONF_MODEL],
62 self, user_input: dict[str, Any] |
None =
None
63 ) -> ConfigFlowResult:
64 """Confirm discovery."""
65 if user_input
is not None:
68 title=self.data[CONF_MODEL],
69 data={CONF_HOST: self.data[CONF_HOST]},
74 step_id=
"discovery_confirm",
75 description_placeholders={
76 "model": self.data[CONF_MODEL],
81 self, user_input: dict[str, Any] |
None =
None
82 ) -> ConfigFlowResult:
83 """Handle a flow initialized by the user."""
84 errors: dict[str, str] = {}
87 self.
clientclient = AirGradientClient(user_input[CONF_HOST], session=session)
89 current_measures = await self.
clientclient.get_current_measures()
90 except AirGradientParseError:
92 except AirGradientError:
93 errors[
"base"] =
"cannot_connect"
96 current_measures.serial_number, raise_on_progress=
False
101 title=current_measures.model,
102 data={CONF_HOST: user_input[CONF_HOST]},
106 data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_discovery_confirm(self, dict[str, Any]|None user_input=None)
None set_configuration_source(self)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo 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_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)
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)