1 """Config flow for the Daikin platform."""
3 from __future__
import annotations
10 from aiohttp
import ClientError, web_exceptions
11 from pydaikin.daikin_base
import Appliance
12 from pydaikin.discovery
import Discovery
13 from pydaikin.exceptions
import DaikinException
14 from pydaikin.factory
import DaikinFactory
15 import voluptuous
as vol
22 from .const
import DOMAIN, KEY_MAC, TIMEOUT
24 _LOGGER = logging.getLogger(__name__)
28 """Handle a config flow."""
33 """Initialize the Daikin config flow."""
34 self.
hosthost: str |
None =
None
38 """Return current schema."""
41 vol.Required(CONF_HOST, default=self.
hosthost): str,
42 vol.Optional(CONF_API_KEY): str,
43 vol.Optional(CONF_PASSWORD): str,
51 key: str |
None =
None,
52 uuid: str |
None =
None,
53 password: str |
None =
None,
54 ) -> ConfigFlowResult:
55 """Register new entry."""
67 CONF_PASSWORD: password,
72 self, host: str, key: str |
None =
None, password: str |
None =
None
73 ) -> ConfigFlowResult:
86 async
with asyncio.timeout(TIMEOUT):
87 device: Appliance = await DaikinFactory(
94 except (TimeoutError, ClientError):
98 data_schema=self.
schemaschema,
99 errors={
"base":
"cannot_connect"},
101 except web_exceptions.HTTPForbidden:
104 data_schema=self.
schemaschema,
105 errors={
"base":
"invalid_auth"},
107 except DaikinException
as daikin_exp:
108 _LOGGER.error(daikin_exp)
111 data_schema=self.
schemaschema,
112 errors={
"base":
"unknown"},
115 _LOGGER.exception(
"Unexpected error creating device")
118 data_schema=self.
schemaschema,
119 errors={
"base":
"unknown"},
123 return await self.
_create_entry_create_entry(host, mac, key, uuid, password)
126 self, user_input: dict[str, Any] |
None =
None
127 ) -> ConfigFlowResult:
128 """User initiated config flow."""
129 if user_input
is None:
131 if user_input.get(CONF_API_KEY)
and user_input.get(CONF_PASSWORD):
132 self.
hosthost = user_input[CONF_HOST]
135 data_schema=self.
schemaschema,
136 errors={
"base":
"api_password"},
139 user_input[CONF_HOST],
140 user_input.get(CONF_API_KEY),
141 user_input.get(CONF_PASSWORD),
145 self, discovery_info: zeroconf.ZeroconfServiceInfo
146 ) -> ConfigFlowResult:
147 """Prepare configuration for a discovered Daikin device."""
148 _LOGGER.debug(
"Zeroconf user_input: %s", discovery_info)
149 devices = Discovery().poll(ip=discovery_info.host)
153 "Could not find MAC-address for %s, make sure the required UDP"
154 " ports are open (see integration documentation)"
161 self.
hosthost = discovery_info.host
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult _create_device(self, str host, str|None key=None, str|None password=None)
ConfigFlowResult _create_entry(self, str host, str mac, str|None key=None, str|None uuid=None, str|None password=None)
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_step_user(self, dict[str, Any]|None user_input=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)