mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use honeywell keys for unique IDs (#69858)
This commit is contained in:
parent
c76b21e24e
commit
77efe385b7
@ -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."""
|
"""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]
|
username = config_entry.data[CONF_USERNAME]
|
||||||
password = config.data[CONF_PASSWORD]
|
password = config_entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
client = await hass.async_add_executor_job(
|
client = await hass.async_add_executor_job(
|
||||||
get_somecomfort_client, username, password
|
get_somecomfort_client, username, password
|
||||||
@ -58,8 +58,8 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
|
|||||||
if client is None:
|
if client is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
loc_id = config.data.get(CONF_LOC_ID)
|
loc_id = config_entry.data.get(CONF_LOC_ID)
|
||||||
dev_id = config.data.get(CONF_DEV_ID)
|
dev_id = config_entry.data.get(CONF_DEV_ID)
|
||||||
|
|
||||||
devices = {}
|
devices = {}
|
||||||
|
|
||||||
@ -73,31 +73,33 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
|
|||||||
_LOGGER.debug("No devices found")
|
_LOGGER.debug("No devices found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
data = HoneywellData(hass, config, client, username, password, devices)
|
data = HoneywellData(hass, config_entry, client, username, password, devices)
|
||||||
await data.async_update()
|
await data.async_update()
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config.entry_id] = data
|
hass.data[DOMAIN][config_entry.entry_id] = data
|
||||||
hass.config_entries.async_setup_platforms(config, PLATFORMS)
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(hass: HomeAssistant, config: ConfigEntry) -> None:
|
async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||||
"""Update listener."""
|
"""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 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:
|
if unload_ok:
|
||||||
hass.data.pop(DOMAIN)
|
hass.data.pop(DOMAIN)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
def get_somecomfort_client(username, password):
|
def get_somecomfort_client(username: str, password: str) -> somecomfort.SomeComfort:
|
||||||
"""Initialize the somecomfort client."""
|
"""Initialize the somecomfort client."""
|
||||||
try:
|
try:
|
||||||
return somecomfort.SomeComfort(username, password)
|
return somecomfort.SomeComfort(username, password)
|
||||||
@ -115,10 +117,18 @@ def get_somecomfort_client(username, password):
|
|||||||
class HoneywellData:
|
class HoneywellData:
|
||||||
"""Get the latest data and update."""
|
"""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."""
|
"""Initialize the data object."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._config = config
|
self._config = config_entry
|
||||||
self._client = client
|
self._client = client
|
||||||
self._username = username
|
self._username = username
|
||||||
self._password = password
|
self._password = password
|
||||||
|
@ -13,7 +13,10 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
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 homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import DOMAIN, HUMIDITY_STATUS_KEY, TEMPERATURE_STATUS_KEY
|
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."""
|
"""Set up the Honeywell thermostat."""
|
||||||
data = hass.data[DOMAIN][config.entry_id]
|
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
for device in data.devices.values():
|
for device in data.devices.values():
|
||||||
@ -81,7 +88,7 @@ class HoneywellSensor(SensorEntity):
|
|||||||
"""Initialize the outdoor temperature sensor."""
|
"""Initialize the outdoor temperature sensor."""
|
||||||
self._device = device
|
self._device = device
|
||||||
self.entity_description = description
|
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_name = f"{device.name} outdoor {description.device_class}"
|
||||||
self._attr_native_unit_of_measurement = description.unit_fn(device)
|
self._attr_native_unit_of_measurement = description.unit_fn(device)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user