1 """Config flow to configure ecobee."""
7 ECOBEE_CONFIG_FILENAME,
11 import voluptuous
as vol
18 from .const
import _LOGGER, CONF_REFRESH_TOKEN, DATA_ECOBEE_CONFIG, DOMAIN
22 """Handle an ecobee config flow."""
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle a flow initiated by the user."""
34 self.hass.data[DATA_ECOBEE_CONFIG].
get(CONF_API_KEY)
35 if DATA_ECOBEE_CONFIG
in self.hass.data
39 if user_input
is not None:
41 self.
_ecobee_ecobee = Ecobee(config={ECOBEE_API_KEY: user_input[CONF_API_KEY]})
43 if await self.hass.async_add_executor_job(self.
_ecobee_ecobee.request_pin):
46 errors[
"base"] =
"pin_request_failed"
50 data_schema=vol.Schema(
51 {vol.Required(CONF_API_KEY, default=stored_api_key): str}
57 self, user_input: dict[str, Any] |
None =
None
58 ) -> ConfigFlowResult:
59 """Present the user with the PIN so that the app can be authorized on ecobee.com."""
62 if user_input
is not None:
64 if await self.hass.async_add_executor_job(self.
_ecobee_ecobee.request_tokens):
67 CONF_API_KEY: self.
_ecobee_ecobee.api_key,
68 CONF_REFRESH_TOKEN: self.
_ecobee_ecobee.refresh_token,
71 errors[
"base"] =
"token_request_failed"
76 description_placeholders={
"pin": self.
_ecobee_ecobee.pin},
80 """Import ecobee config from configuration.yaml.
82 Triggered by async_setup only if a config entry doesn't already exist.
83 If ecobee.conf exists, we will attempt to validate the credentials
84 and create an entry if valid. Otherwise, we will delegate to the user
85 step so that the user can continue the config flow.
88 legacy_config = await self.hass.async_add_executor_job(
89 load_json_object, self.hass.config.path(ECOBEE_CONFIG_FILENAME)
92 ECOBEE_API_KEY: legacy_config[ECOBEE_API_KEY],
93 ECOBEE_REFRESH_TOKEN: legacy_config[ECOBEE_REFRESH_TOKEN],
95 except (HomeAssistantError, KeyError):
97 "No valid ecobee.conf configuration found for import, delegating to"
102 CONF_API_KEY: self.hass.data[DATA_ECOBEE_CONFIG].
get(CONF_API_KEY)
106 ecobee = Ecobee(config=config)
107 if await self.hass.async_add_executor_job(ecobee.refresh_tokens):
110 "Valid ecobee configuration found for import, creating configuration"
116 CONF_API_KEY: ecobee.api_key,
117 CONF_REFRESH_TOKEN: ecobee.refresh_token,
122 CONF_API_KEY: self.hass.data[DATA_ECOBEE_CONFIG].
get(CONF_API_KEY)
ConfigFlowResult async_step_import(self, None import_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_authorize(self, dict[str, Any]|None user_input=None)
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)
web.Response get(self, web.Request request, str config_key)