mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Move lyric base entity to separate module (#126493)
This commit is contained in:
parent
26651c18a6
commit
acd3b2d732
@ -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
|
||||
)
|
||||
|
@ -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__)
|
||||
|
||||
|
114
homeassistant/components/lyric/entity.py
Normal file
114
homeassistant/components/lyric/entity.py
Normal file
@ -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
|
||||
)
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user