diff --git a/homeassistant/components/lyric/__init__.py b/homeassistant/components/lyric/__init__.py index 6c35e084424..b338605a6ea 100644 --- a/homeassistant/components/lyric/__init__.py +++ b/homeassistant/components/lyric/__init__.py @@ -10,9 +10,6 @@ import logging from aiohttp.client_exceptions import ClientResponseError from aiolyric import Lyric from aiolyric.exceptions import LyricAuthenticationException, LyricException -from aiolyric.objects.device import LyricDevice -from aiolyric.objects.location import LyricLocation -from aiolyric.objects.priority import LyricAccessory, LyricRoom from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform @@ -22,14 +19,8 @@ from homeassistant.helpers import ( aiohttp_client, config_entry_oauth2_flow, config_validation as cv, - device_registry as dr, -) -from homeassistant.helpers.device_registry import DeviceInfo -from homeassistant.helpers.update_coordinator import ( - CoordinatorEntity, - DataUpdateCoordinator, - UpdateFailed, ) +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .api import ( ConfigEntryLyricClient, @@ -127,102 +118,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok - - -class LyricEntity(CoordinatorEntity[DataUpdateCoordinator[Lyric]]): - """Defines a base Honeywell Lyric entity.""" - - _attr_has_entity_name = True - - def __init__( - self, - coordinator: DataUpdateCoordinator[Lyric], - location: LyricLocation, - device: LyricDevice, - key: str, - ) -> None: - """Initialize the Honeywell Lyric entity.""" - super().__init__(coordinator) - self._key = key - self._location = location - self._mac_id = device.mac_id - self._update_thermostat = coordinator.data.update_thermostat - self._update_fan = coordinator.data.update_fan - - @property - def unique_id(self) -> str: - """Return the unique ID for this entity.""" - return self._key - - @property - def location(self) -> LyricLocation: - """Get the Lyric Location.""" - return self.coordinator.data.locations_dict[self._location.location_id] - - @property - def device(self) -> LyricDevice: - """Get the Lyric Device.""" - return self.location.devices_dict[self._mac_id] - - -class LyricDeviceEntity(LyricEntity): - """Defines a Honeywell Lyric device entity.""" - - @property - def device_info(self) -> DeviceInfo: - """Return device information about this Honeywell Lyric instance.""" - return DeviceInfo( - identifiers={(dr.CONNECTION_NETWORK_MAC, self._mac_id)}, - connections={(dr.CONNECTION_NETWORK_MAC, self._mac_id)}, - manufacturer="Honeywell", - model=self.device.device_model, - name=f"{self.device.name} Thermostat", - ) - - -class LyricAccessoryEntity(LyricDeviceEntity): - """Defines a Honeywell Lyric accessory entity, a sub-device of a thermostat.""" - - def __init__( - self, - coordinator: DataUpdateCoordinator[Lyric], - location: LyricLocation, - device: LyricDevice, - room: LyricRoom, - accessory: LyricAccessory, - key: str, - ) -> None: - """Initialize the Honeywell Lyric accessory entity.""" - super().__init__(coordinator, location, device, key) - self._room_id = room.id - self._accessory_id = accessory.id - - @property - def device_info(self) -> DeviceInfo: - """Return device information about this Honeywell Lyric instance.""" - return DeviceInfo( - identifiers={ - ( - f"{dr.CONNECTION_NETWORK_MAC}_room_accessory", - f"{self._mac_id}_room{self._room_id}_accessory{self._accessory_id}", - ) - }, - manufacturer="Honeywell", - model="RCHTSENSOR", - name=f"{self.room.room_name} Sensor", - via_device=(dr.CONNECTION_NETWORK_MAC, self._mac_id), - ) - - @property - def room(self) -> LyricRoom: - """Get the Lyric Device.""" - return self.coordinator.data.rooms_dict[self._mac_id][self._room_id] - - @property - def accessory(self) -> LyricAccessory: - """Get the Lyric Device.""" - return next( - accessory - for accessory in self.room.accessories - if accessory.id == self._accessory_id - ) diff --git a/homeassistant/components/lyric/climate.py b/homeassistant/components/lyric/climate.py index 22ab8ba57d4..37810f33256 100644 --- a/homeassistant/components/lyric/climate.py +++ b/homeassistant/components/lyric/climate.py @@ -40,7 +40,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import VolDictType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from . import LyricDeviceEntity from .const import ( DOMAIN, LYRIC_EXCEPTIONS, @@ -50,6 +49,7 @@ from .const import ( PRESET_TEMPORARY_HOLD, PRESET_VACATION_HOLD, ) +from .entity import LyricDeviceEntity _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/lyric/entity.py b/homeassistant/components/lyric/entity.py new file mode 100644 index 00000000000..5a5a76f1442 --- /dev/null +++ b/homeassistant/components/lyric/entity.py @@ -0,0 +1,114 @@ +"""The Honeywell Lyric integration.""" + +from __future__ import annotations + +from aiolyric import Lyric +from aiolyric.objects.device import LyricDevice +from aiolyric.objects.location import LyricLocation +from aiolyric.objects.priority import LyricAccessory, LyricRoom + +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, +) + + +class LyricEntity(CoordinatorEntity[DataUpdateCoordinator[Lyric]]): + """Defines a base Honeywell Lyric entity.""" + + _attr_has_entity_name = True + + def __init__( + self, + coordinator: DataUpdateCoordinator[Lyric], + location: LyricLocation, + device: LyricDevice, + key: str, + ) -> None: + """Initialize the Honeywell Lyric entity.""" + super().__init__(coordinator) + self._key = key + self._location = location + self._mac_id = device.mac_id + self._update_thermostat = coordinator.data.update_thermostat + self._update_fan = coordinator.data.update_fan + + @property + def unique_id(self) -> str: + """Return the unique ID for this entity.""" + return self._key + + @property + def location(self) -> LyricLocation: + """Get the Lyric Location.""" + return self.coordinator.data.locations_dict[self._location.location_id] + + @property + def device(self) -> LyricDevice: + """Get the Lyric Device.""" + return self.location.devices_dict[self._mac_id] + + +class LyricDeviceEntity(LyricEntity): + """Defines a Honeywell Lyric device entity.""" + + @property + def device_info(self) -> DeviceInfo: + """Return device information about this Honeywell Lyric instance.""" + return DeviceInfo( + identifiers={(dr.CONNECTION_NETWORK_MAC, self._mac_id)}, + connections={(dr.CONNECTION_NETWORK_MAC, self._mac_id)}, + manufacturer="Honeywell", + model=self.device.device_model, + name=f"{self.device.name} Thermostat", + ) + + +class LyricAccessoryEntity(LyricDeviceEntity): + """Defines a Honeywell Lyric accessory entity, a sub-device of a thermostat.""" + + def __init__( + self, + coordinator: DataUpdateCoordinator[Lyric], + location: LyricLocation, + device: LyricDevice, + room: LyricRoom, + accessory: LyricAccessory, + key: str, + ) -> None: + """Initialize the Honeywell Lyric accessory entity.""" + super().__init__(coordinator, location, device, key) + self._room_id = room.id + self._accessory_id = accessory.id + + @property + def device_info(self) -> DeviceInfo: + """Return device information about this Honeywell Lyric instance.""" + return DeviceInfo( + identifiers={ + ( + f"{dr.CONNECTION_NETWORK_MAC}_room_accessory", + f"{self._mac_id}_room{self._room_id}_accessory{self._accessory_id}", + ) + }, + manufacturer="Honeywell", + model="RCHTSENSOR", + name=f"{self.room.room_name} Sensor", + via_device=(dr.CONNECTION_NETWORK_MAC, self._mac_id), + ) + + @property + def room(self) -> LyricRoom: + """Get the Lyric Device.""" + return self.coordinator.data.rooms_dict[self._mac_id][self._room_id] + + @property + def accessory(self) -> LyricAccessory: + """Get the Lyric Device.""" + return next( + accessory + for accessory in self.room.accessories + if accessory.id == self._accessory_id + ) diff --git a/homeassistant/components/lyric/sensor.py b/homeassistant/components/lyric/sensor.py index 7e006bc7bfe..38cb895a110 100644 --- a/homeassistant/components/lyric/sensor.py +++ b/homeassistant/components/lyric/sensor.py @@ -25,7 +25,6 @@ from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.util import dt as dt_util -from . import LyricAccessoryEntity, LyricDeviceEntity from .const import ( DOMAIN, PRESET_HOLD_UNTIL, @@ -34,6 +33,7 @@ from .const import ( PRESET_TEMPORARY_HOLD, PRESET_VACATION_HOLD, ) +from .entity import LyricAccessoryEntity, LyricDeviceEntity LYRIC_SETPOINT_STATUS_NAMES = { PRESET_NO_HOLD: "Following Schedule",