-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Ecobee username/password authentication #161716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,15 +2,21 @@ | |||||||||||||
|
|
||||||||||||||
| from typing import Any | ||||||||||||||
|
|
||||||||||||||
| from pyecobee import ECOBEE_API_KEY, Ecobee | ||||||||||||||
| from pyecobee import ECOBEE_API_KEY, ECOBEE_PASSWORD, ECOBEE_USERNAME, Ecobee | ||||||||||||||
| import voluptuous as vol | ||||||||||||||
|
|
||||||||||||||
| from homeassistant.config_entries import ConfigFlow, ConfigFlowResult | ||||||||||||||
| from homeassistant.const import CONF_API_KEY | ||||||||||||||
| from homeassistant.const import CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME | ||||||||||||||
|
|
||||||||||||||
| from .const import CONF_REFRESH_TOKEN, DOMAIN | ||||||||||||||
|
|
||||||||||||||
| _USER_SCHEMA = vol.Schema({vol.Required(CONF_API_KEY): str}) | ||||||||||||||
| _USER_SCHEMA = vol.Schema( | ||||||||||||||
| { | ||||||||||||||
| vol.Optional(CONF_API_KEY): str, | ||||||||||||||
| vol.Optional(CONF_USERNAME): str, | ||||||||||||||
| vol.Optional(CONF_PASSWORD): str, | ||||||||||||||
| } | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class EcobeeFlowHandler(ConfigFlow, domain=DOMAIN): | ||||||||||||||
|
|
@@ -27,13 +33,34 @@ async def async_step_user( | |||||||||||||
| errors = {} | ||||||||||||||
|
|
||||||||||||||
| if user_input is not None: | ||||||||||||||
| # Use the user-supplied API key to attempt to obtain a PIN from ecobee. | ||||||||||||||
| self._ecobee = Ecobee(config={ECOBEE_API_KEY: user_input[CONF_API_KEY]}) | ||||||||||||||
|
|
||||||||||||||
| if await self.hass.async_add_executor_job(self._ecobee.request_pin): | ||||||||||||||
| # We have a PIN; move to the next step of the flow. | ||||||||||||||
| return await self.async_step_authorize() | ||||||||||||||
| errors["base"] = "pin_request_failed" | ||||||||||||||
| api_key = user_input.get(CONF_API_KEY) | ||||||||||||||
| username = user_input.get(CONF_USERNAME) | ||||||||||||||
| password = user_input.get(CONF_PASSWORD) | ||||||||||||||
|
|
||||||||||||||
| if api_key and not (username or password): | ||||||||||||||
| # Use the user-supplied API key to attempt to obtain a PIN from ecobee. | ||||||||||||||
| self._ecobee = Ecobee(config={ECOBEE_API_KEY: api_key}) | ||||||||||||||
| if await self.hass.async_add_executor_job(self._ecobee.request_pin): | ||||||||||||||
| # We have a PIN; move to the next step of the flow. | ||||||||||||||
| return await self.async_step_authorize() | ||||||||||||||
| errors["base"] = "pin_request_failed" | ||||||||||||||
| elif username and password and not api_key: | ||||||||||||||
| self._ecobee = Ecobee( | ||||||||||||||
| config={ | ||||||||||||||
| ECOBEE_USERNAME: username, | ||||||||||||||
| ECOBEE_PASSWORD: password, | ||||||||||||||
| } | ||||||||||||||
| ) | ||||||||||||||
| if await self.hass.async_add_executor_job(self._ecobee.refresh_tokens): | ||||||||||||||
| config = { | ||||||||||||||
| CONF_USERNAME: username, | ||||||||||||||
| CONF_PASSWORD: password, | ||||||||||||||
| CONF_REFRESH_TOKEN: self._ecobee.refresh_token, | ||||||||||||||
| } | ||||||||||||||
| return self.async_create_entry(title=DOMAIN, data=config) | ||||||||||||||
| errors["base"] = "login_failed" | ||||||||||||||
| else: | ||||||||||||||
| errors["base"] = "invalid_auth" | ||||||||||||||
|
Comment on lines
+61
to
+63
|
||||||||||||||
| errors["base"] = "login_failed" | |
| else: | |
| errors["base"] = "invalid_auth" | |
| errors["base"] = "token_request_failed" | |
| else: | |
| errors["base"] = "pin_request_failed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_USER_SCHEMAnow allows either an API key or a username/password pair, but theconfig.step.userdescription and field definitions instrings.jsonstill only mention entering an API key. To keep the UI consistent with the actual behavior, please update the user-step description (and, if needed, data field text) to explain that users can authenticate either with an API key or with their Ecobee account credentials.