1
mirror of https://github.com/home-assistant/core synced 2024-07-27 18:58:57 +02:00
ha-core/homeassistant/components/nexia/__init__.py

95 lines
3.4 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 03:03:51 +01:00
"""Support for Nexia / Trane XL Thermostats."""
2022-05-19 01:08:02 +02:00
import asyncio
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 03:03:51 +01:00
import logging
2022-05-19 01:08:02 +02:00
import aiohttp
from nexia.const import 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 03:03:51 +01:00
from nexia.home import NexiaHome
from nexia.thermostat import NexiaThermostat
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 03:03:51 +01:00
from homeassistant.config_entries import ConfigEntry
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 03:03:51 +01:00
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
2022-05-19 01:08:02 +02:00
from homeassistant.helpers.aiohttp_client import async_get_clientsession
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 03:03:51 +01:00
import homeassistant.helpers.config_validation as cv
from .const import CONF_BRAND, DOMAIN, PLATFORMS
from .coordinator import NexiaDataUpdateCoordinator
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 03:03:51 +01:00
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
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 03:03:51 +01:00
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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 03:03:51 +01:00
"""Configure the base Nexia device for Home Assistant."""
conf = entry.data
username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
brand = conf.get(CONF_BRAND, 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 03:03:51 +01:00
state_file = hass.config.path(f"nexia_config_{username}.conf")
2022-05-19 01:08:02 +02:00
session = async_get_clientsession(hass)
nexia_home = NexiaHome(
session,
username=username,
password=password,
device_name=hass.config.location_name,
state_file=state_file,
brand=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 03:03:51 +01:00
try:
2022-05-19 01:08:02 +02:00
await nexia_home.login()
except asyncio.TimeoutError as ex:
raise ConfigEntryNotReady(
f"Timed out trying to connect to Nexia service: {ex}"
) from ex
except aiohttp.ClientResponseError as http_ex:
if is_invalid_auth_code(http_ex.status):
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 03:03:51 +01:00
_LOGGER.error(
"Access error from Nexia service, please check credentials: %s", 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 03:03:51 +01:00
)
return False
2022-05-19 01:08:02 +02:00
raise ConfigEntryNotReady(f"Error from Nexia service: {http_ex}") from http_ex
Fix not retrying on connection reset during nexia config entry setup (#93576) * Fix not retrying on connection reset during nexia config entry setup fixes ``` 2023-05-26 00:15:39.129 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Alexander for nexia Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 558, in _request resp = await req.send(conn) ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 670, in send await writer.write_headers(status_line, self.headers) File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 130, in write_headers self._write(buf) File "/usr/local/lib/python3.11/site-packages/aiohttp/http_writer.py", line 75, in _write raise ConnectionResetError("Cannot write to closing transport") ConnectionResetError: Cannot write to closing transport The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/nexia/__init__.py", line 47, in async_setup_entry await nexia_home.login() File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 385, in login request = await self.post_url(self.API_MOBILE_ACCOUNTS_SIGN_IN_URL, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/nexia/home.py", line 157, in post_url response: aiohttp.ClientResponse = await self.session.post( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 572, in _request raise ClientOSError(*exc.args) from exc aiohttp.client_exceptions.ClientOSError: Cannot write to closing transport ``` * coverage
2023-05-26 03:52:44 +02:00
except aiohttp.ClientOSError as os_error:
raise ConfigEntryNotReady(
f"Error connecting to Nexia service: {os_error}"
) from os_error
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 03:03:51 +01:00
coordinator = NexiaDataUpdateCoordinator(hass, nexia_home)
2022-05-19 01:08:02 +02:00
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
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 03:03:51 +01:00
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
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 03:03:51 +01:00
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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 03:03:51 +01:00
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
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 03:03:51 +01:00
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok
async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
"""Remove a nexia config entry from a device."""
coordinator: NexiaDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
nexia_home: NexiaHome = coordinator.nexia_home
dev_ids = {dev_id[1] for dev_id in device_entry.identifiers if dev_id[0] == DOMAIN}
for thermostat_id in nexia_home.get_thermostat_ids():
if thermostat_id in dev_ids:
return False
thermostat: NexiaThermostat = nexia_home.get_thermostat_by_id(thermostat_id)
for zone_id in thermostat.get_zone_ids():
if zone_id in dev_ids:
return False
return True