1 """Adds config flow for AccuWeather."""
3 from __future__
import annotations
5 from asyncio
import timeout
8 from accuweather
import AccuWeather, ApiError, InvalidApiKeyError, RequestsExceededError
9 from aiohttp
import ClientError
10 from aiohttp.client_exceptions
import ClientConnectorError
11 import voluptuous
as vol
18 from .const
import DOMAIN
22 """Config flow for AccuWeather."""
27 self, user_input: dict[str, Any] |
None =
None
28 ) -> ConfigFlowResult:
29 """Handle a flow initialized by the user."""
32 if user_input
is not None:
35 async
with timeout(10):
36 accuweather = AccuWeather(
37 user_input[CONF_API_KEY],
39 latitude=user_input[CONF_LATITUDE],
40 longitude=user_input[CONF_LONGITUDE],
42 await accuweather.async_get_location()
43 except (ApiError, ClientConnectorError, TimeoutError, ClientError):
44 errors[
"base"] =
"cannot_connect"
45 except InvalidApiKeyError:
46 errors[CONF_API_KEY] =
"invalid_api_key"
47 except RequestsExceededError:
48 errors[CONF_API_KEY] =
"requests_exceeded"
51 accuweather.location_key, raise_on_progress=
False
55 title=user_input[CONF_NAME], data=user_input
60 data_schema=vol.Schema(
62 vol.Required(CONF_API_KEY): str,
64 CONF_LATITUDE, default=self.hass.config.latitude
67 CONF_LONGITUDE, default=self.hass.config.longitude
70 CONF_NAME, default=self.hass.config.location_name
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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_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)
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)