1 """Support for Nexia / Trane XL Thermostats."""
6 from nexia.const
import BRAND_NEXIA
7 from nexia.home
import NexiaHome
8 from nexia.thermostat
import NexiaThermostat
16 from .const
import CONF_BRAND, DOMAIN, PLATFORMS
17 from .coordinator
import NexiaDataUpdateCoordinator
18 from .types
import NexiaConfigEntry
19 from .util
import is_invalid_auth_code
21 _LOGGER = logging.getLogger(__name__)
25 """Configure the base Nexia device for Home Assistant."""
28 username = conf[CONF_USERNAME]
29 password = conf[CONF_PASSWORD]
30 brand = conf.get(CONF_BRAND, BRAND_NEXIA)
32 state_file = hass.config.path(f
"nexia_config_{username}.conf")
34 nexia_home = NexiaHome(
38 device_name=hass.config.location_name,
39 state_file=state_file,
44 await nexia_home.login()
45 except TimeoutError
as ex:
47 f
"Timed out trying to connect to Nexia service: {ex}"
49 except aiohttp.ClientResponseError
as http_ex:
52 "Access error from Nexia service, please check credentials: %s", http_ex
56 except aiohttp.ClientOSError
as os_error:
58 f
"Error connecting to Nexia service: {os_error}"
62 await coordinator.async_config_entry_first_refresh()
63 entry.runtime_data = coordinator
64 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
70 """Unload a config entry."""
71 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
75 hass: HomeAssistant, entry: NexiaConfigEntry, device_entry: dr.DeviceEntry
77 """Remove a nexia config entry from a device."""
78 coordinator = entry.runtime_data
79 nexia_home = coordinator.nexia_home
80 dev_ids = {dev_id[1]
for dev_id
in device_entry.identifiers
if dev_id[0] == DOMAIN}
81 for thermostat_id
in nexia_home.get_thermostat_ids():
82 if thermostat_id
in dev_ids:
84 thermostat: NexiaThermostat = nexia_home.get_thermostat_by_id(thermostat_id)
85 for zone_id
in thermostat.get_zone_ids():
86 if zone_id
in dev_ids:
94 _LOGGER.debug(
"Migrating from version %s", entry.version)
96 if entry.version == 1:
98 if entry.minor_version == 1:
100 hass.config_entries.async_update_entry(
101 entry, unique_id=
str(entry.unique_id), minor_version=minor_version
104 _LOGGER.debug(
"Migration successful")
def is_invalid_auth_code(http_status_code)
bool async_remove_config_entry_device(HomeAssistant hass, NexiaConfigEntry entry, dr.DeviceEntry device_entry)
bool async_unload_entry(HomeAssistant hass, NexiaConfigEntry entry)
bool async_migrate_entry(HomeAssistant hass, NexiaConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, NexiaConfigEntry entry)
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)