core/homeassistant/components/nexia/config_flow.py

98 lines
3.2 KiB
Python
Raw Normal View History

Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
"""Config flow for Nexia integration."""
import logging
from nexia.const import BRAND_ASAIR, BRAND_NEXIA
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
from nexia.home import NexiaHome
from requests.exceptions import ConnectTimeout, HTTPError
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
from .const import BRAND_ASAIR_NAME, BRAND_NEXIA_NAME, CONF_BRAND, DOMAIN
from .util import is_invalid_auth_code
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_BRAND, default=BRAND_NEXIA): vol.In(
{BRAND_NEXIA: BRAND_NEXIA_NAME, BRAND_ASAIR: BRAND_ASAIR_NAME}
),
}
)
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
state_file = hass.config.path(f"nexia_config_{data[CONF_USERNAME]}.conf")
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
try:
nexia_home = NexiaHome(
username=data[CONF_USERNAME],
password=data[CONF_PASSWORD],
brand=data[CONF_BRAND],
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
auto_login=False,
auto_update=False,
device_name=hass.config.location_name,
state_file=state_file,
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
)
await hass.async_add_executor_job(nexia_home.login)
except ConnectTimeout as ex:
_LOGGER.error("Unable to connect to Nexia service: %s", ex)
raise CannotConnect from ex
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
except HTTPError as http_ex:
_LOGGER.error("HTTP error from Nexia service: %s", http_ex)
if is_invalid_auth_code(http_ex.response.status_code):
raise InvalidAuth from http_ex
raise CannotConnect from http_ex
Add Nexia thermostat support (Trane / American Standard) (#32826) * Merge nexia * Restore original work * Merge cleanups * config flow * Add config flow * Add missing files * Fix import of old yaml config * More cleanups from self review * Additional self review * Update homeassistant/components/nexia/services.yaml Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * fix io in event loop * Update homeassistant/components/nexia/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * avoid using ternary statements if they span multiple * Cleanup strings and remove unneeded attributes * more cleanup * more cleanup of yaml * remove coordinator boiler plate * nuke services for now for the inital pr, add back later * remove copy pasta * this can be reduced more * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * review * comments * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/nexia/climate.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * more review adjustments * nuke unused constants * Update homeassistant/components/nexia/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * map states * add update * zone id is unique * Fix humidfy check * target_humidity should be a property instead of in attributes * remove aux heat as its already there Co-authored-by: Ryan Nazaretian <ryannazaretian@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-03-20 02:03:51 +00:00
if not nexia_home.get_name():
raise InvalidAuth
info = {"title": nexia_home.get_name(), "house_id": nexia_home.house_id}
_LOGGER.debug("Setup ok with info: %s", info)
return info
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Nexia."""
VERSION = 1
async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
if "base" not in errors:
await self.async_set_unique_id(info["house_id"])
self._abort_if_unique_id_configured()
return self.async_create_entry(title=info["title"], data=user_input)
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)
class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""
class InvalidAuth(exceptions.HomeAssistantError):
"""Error to indicate there is invalid auth."""