1 """Config flow for Tomorrow.io integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from pytomorrowio.exceptions
import (
11 InvalidAPIKeyException,
14 from pytomorrowio.pytomorrowio
import TomorrowioV4
15 import voluptuous
as vol
41 TMRW_ATTR_TEMPERATURE,
44 _LOGGER = logging.getLogger(__name__)
50 input_dict: dict[str, Any] |
None =
None,
52 """Return schema defaults for init step based on user input/config dict.
54 Retain info already provided for future form views by setting them as
57 if input_dict
is None:
61 vol.Required(CONF_API_KEY, default=input_dict.get(CONF_API_KEY)): str,
64 default_location = input_dict.get(
67 CONF_LATITUDE: hass.config.latitude,
68 CONF_LONGITUDE: hass.config.longitude,
76 default=default_location,
83 """Return unique ID from config data."""
85 f
"{input_dict[CONF_API_KEY]}"
86 f
"_{input_dict[CONF_LOCATION][CONF_LATITUDE]}"
87 f
"_{input_dict[CONF_LOCATION][CONF_LONGITUDE]}"
92 """Handle Tomorrow.io options."""
95 self, user_input: dict[str, Any] |
None =
None
96 ) -> ConfigFlowResult:
97 """Manage the Tomorrow.io options."""
98 if user_input
is not None:
105 ): vol.In([1, 5, 15, 30, 60]),
109 step_id=
"init", data_schema=vol.Schema(options_schema)
114 """Handle a config flow for Tomorrow.io Weather API."""
121 config_entry: ConfigEntry,
122 ) -> TomorrowioOptionsConfigFlow:
123 """Get the options flow for this handler."""
127 self, user_input: dict[str, Any] |
None =
None
128 ) -> ConfigFlowResult:
129 """Handle the initial step."""
131 if user_input
is not None:
137 location = user_input[CONF_LOCATION]
138 latitude = location[CONF_LATITUDE]
139 longitude = location[CONF_LONGITUDE]
140 if CONF_NAME
not in user_input:
141 user_input[CONF_NAME] = DEFAULT_NAME
144 zone_name = zone_state.attributes[CONF_FRIENDLY_NAME]
145 user_input[CONF_NAME] += f
" - {zone_name}"
148 user_input[CONF_API_KEY],
152 ).realtime([TMRW_ATTR_TEMPERATURE])
153 except CantConnectException:
154 errors[
"base"] =
"cannot_connect"
155 except InvalidAPIKeyException:
156 errors[CONF_API_KEY] =
"invalid_api_key"
157 except RateLimitedException:
158 errors[CONF_API_KEY] =
"rate_limited"
160 _LOGGER.exception(
"Unexpected exception")
161 errors[
"base"] =
"unknown"
164 options: Mapping[str, Any] = {CONF_TIMESTEP: DEFAULT_TIMESTEP}
166 title=user_input[CONF_NAME],
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
TomorrowioOptionsConfigFlow async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=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_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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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 _get_unique_id(HomeAssistant hass, dict[str, Any] input_dict)
vol.Schema _get_config_schema(HomeAssistant hass, str|None source, dict[str, Any]|None input_dict=None)
State|None async_active_zone(HomeAssistant hass, float latitude, float longitude, int radius=0)
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)