Use honeywell keys for unique IDs (#69858)

This commit is contained in:
RDFurman 2022-04-13 11:17:38 -06:00 committed by GitHub
parent c76b21e24e
commit 77efe385b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 20 deletions

View File

@ -44,12 +44,12 @@ def _async_migrate_data_to_options(
)
async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set up the Honeywell thermostat."""
_async_migrate_data_to_options(hass, config)
_async_migrate_data_to_options(hass, config_entry)
username = config.data[CONF_USERNAME]
password = config.data[CONF_PASSWORD]
username = config_entry.data[CONF_USERNAME]
password = config_entry.data[CONF_PASSWORD]
client = await hass.async_add_executor_job(
get_somecomfort_client, username, password
@ -58,8 +58,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
if client is None:
return False
loc_id = config.data.get(CONF_LOC_ID)
dev_id = config.data.get(CONF_DEV_ID)
loc_id = config_entry.data.get(CONF_LOC_ID)
dev_id = config_entry.data.get(CONF_DEV_ID)
devices = {}
@ -73,31 +73,33 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
_LOGGER.debug("No devices found")
return False
data = HoneywellData(hass, config, client, username, password, devices)
data = HoneywellData(hass, config_entry, client, username, password, devices)
await data.async_update()
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config.entry_id] = data
hass.config_entries.async_setup_platforms(config, PLATFORMS)
hass.data[DOMAIN][config_entry.entry_id] = data
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
config.async_on_unload(config.add_update_listener(update_listener))
config_entry.async_on_unload(config_entry.add_update_listener(update_listener))
return True
async def update_listener(hass: HomeAssistant, config: ConfigEntry) -> None:
async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Update listener."""
await hass.config_entries.async_reload(config.entry_id)
await hass.config_entries.async_reload(config_entry.entry_id)
async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload the config config and platforms."""
unload_ok = await hass.config_entries.async_unload_platforms(config, PLATFORMS)
unload_ok = await hass.config_entries.async_unload_platforms(
config_entry, PLATFORMS
)
if unload_ok:
hass.data.pop(DOMAIN)
return unload_ok
def get_somecomfort_client(username, password):
def get_somecomfort_client(username: str, password: str) -> somecomfort.SomeComfort:
"""Initialize the somecomfort client."""
try:
return somecomfort.SomeComfort(username, password)
@ -115,10 +117,18 @@ def get_somecomfort_client(username, password):
class HoneywellData:
"""Get the latest data and update."""
def __init__(self, hass, config, client, username, password, devices):
def __init__(
self,
hass: HomeAssistant,
config_entry: ConfigEntry,
client: somecomfort.SomeComfort,
username: str,
password: str,
devices: dict[str, somecomfort.Device],
) -> None:
"""Initialize the data object."""
self._hass = hass
self._config = config
self._config = config_entry
self._client = client
self._username = username
self._password = password

View File

@ -13,7 +13,10 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from .const import DOMAIN, HUMIDITY_STATUS_KEY, TEMPERATURE_STATUS_KEY
@ -59,9 +62,13 @@ SENSOR_TYPES: tuple[HoneywellSensorEntityDescription, ...] = (
)
async def async_setup_entry(hass, config, async_add_entities, discovery_info=None):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Honeywell thermostat."""
data = hass.data[DOMAIN][config.entry_id]
data = hass.data[DOMAIN][config_entry.entry_id]
sensors = []
for device in data.devices.values():
@ -81,7 +88,7 @@ class HoneywellSensor(SensorEntity):
"""Initialize the outdoor temperature sensor."""
self._device = device
self.entity_description = description
self._attr_unique_id = f"{device.deviceid}_outdoor_{description.device_class}"
self._attr_unique_id = f"{device.deviceid}_{description.key}"
self._attr_name = f"{device.name} outdoor {description.device_class}"
self._attr_native_unit_of_measurement = description.unit_fn(device)