2022-05-30 17:54:39 +00:00
|
|
|
"""The powerview integration base entity."""
|
2020-04-29 21:24:57 +00:00
|
|
|
|
2024-02-15 14:27:11 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from aiopvapi.resources.shade import BaseShade, ShadePosition
|
2020-05-01 01:25:59 +00:00
|
|
|
|
2020-04-29 21:24:57 +00:00
|
|
|
import homeassistant.helpers.device_registry as dr
|
2023-08-11 02:04:26 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
2020-08-30 18:28:09 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
2020-04-29 21:24:57 +00:00
|
|
|
|
2024-02-15 14:27:11 +00:00
|
|
|
from .const import DOMAIN, MANUFACTURER
|
2022-05-30 17:54:39 +00:00
|
|
|
from .coordinator import PowerviewShadeUpdateCoordinator
|
2022-06-21 16:12:11 +00:00
|
|
|
from .model import PowerviewDeviceInfo
|
2024-02-15 14:27:11 +00:00
|
|
|
from .shade_data import PowerviewShadeData
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2020-04-29 21:24:57 +00:00
|
|
|
|
|
|
|
|
2022-05-30 17:54:39 +00:00
|
|
|
class HDEntity(CoordinatorEntity[PowerviewShadeUpdateCoordinator]):
|
2020-04-29 21:24:57 +00:00
|
|
|
"""Base class for hunter douglas entities."""
|
|
|
|
|
2023-08-14 20:26:20 +00:00
|
|
|
_attr_has_entity_name = True
|
|
|
|
|
2022-05-30 17:54:39 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
coordinator: PowerviewShadeUpdateCoordinator,
|
2022-06-21 16:12:11 +00:00
|
|
|
device_info: PowerviewDeviceInfo,
|
2022-05-30 17:54:39 +00:00
|
|
|
room_name: str,
|
|
|
|
unique_id: str,
|
|
|
|
) -> None:
|
2020-04-29 21:24:57 +00:00
|
|
|
"""Initialize the entity."""
|
2020-08-30 18:28:09 +00:00
|
|
|
super().__init__(coordinator)
|
2021-02-20 06:17:00 +00:00
|
|
|
self._room_name = room_name
|
2022-05-30 17:54:39 +00:00
|
|
|
self._attr_unique_id = unique_id
|
2020-04-29 21:24:57 +00:00
|
|
|
self._device_info = device_info
|
2024-02-15 14:27:11 +00:00
|
|
|
self._configuration_url = self.coordinator.hub.url
|
2020-04-29 21:24:57 +00:00
|
|
|
|
|
|
|
@property
|
2022-05-30 17:54:39 +00:00
|
|
|
def data(self) -> PowerviewShadeData:
|
|
|
|
"""Return the PowerviewShadeData."""
|
|
|
|
return self.coordinator.data
|
2020-04-29 21:24:57 +00:00
|
|
|
|
|
|
|
@property
|
2021-10-23 10:03:14 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2020-04-29 21:24:57 +00:00
|
|
|
"""Return the device_info of the device."""
|
2021-10-23 10:03:14 +00:00
|
|
|
return DeviceInfo(
|
2022-06-21 16:12:11 +00:00
|
|
|
connections={(dr.CONNECTION_NETWORK_MAC, self._device_info.mac_address)},
|
|
|
|
identifiers={(DOMAIN, self._device_info.serial_number)},
|
2021-10-23 13:35:33 +00:00
|
|
|
manufacturer=MANUFACTURER,
|
2022-06-21 16:12:11 +00:00
|
|
|
model=self._device_info.model,
|
|
|
|
name=self._device_info.name,
|
2024-02-15 14:27:11 +00:00
|
|
|
sw_version=self._device_info.firmware,
|
|
|
|
configuration_url=self._configuration_url,
|
2021-10-23 10:03:14 +00:00
|
|
|
)
|
2020-05-01 01:25:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ShadeEntity(HDEntity):
|
|
|
|
"""Base class for hunter douglas shade entities."""
|
|
|
|
|
2022-05-30 17:54:39 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
coordinator: PowerviewShadeUpdateCoordinator,
|
2022-06-21 16:12:11 +00:00
|
|
|
device_info: PowerviewDeviceInfo,
|
2022-05-30 17:54:39 +00:00
|
|
|
room_name: str,
|
|
|
|
shade: BaseShade,
|
|
|
|
shade_name: str,
|
|
|
|
) -> None:
|
2020-05-01 01:25:59 +00:00
|
|
|
"""Initialize the shade."""
|
2021-02-20 06:17:00 +00:00
|
|
|
super().__init__(coordinator, device_info, room_name, shade.id)
|
2020-05-01 01:25:59 +00:00
|
|
|
self._shade_name = shade_name
|
|
|
|
self._shade = shade
|
2024-02-15 14:27:11 +00:00
|
|
|
self._is_hard_wired = not shade.is_battery_powered()
|
|
|
|
self._configuration_url = shade.url
|
2020-05-01 01:25:59 +00:00
|
|
|
|
2022-05-30 17:54:39 +00:00
|
|
|
@property
|
2024-02-15 14:27:11 +00:00
|
|
|
def positions(self) -> ShadePosition:
|
2022-05-30 17:54:39 +00:00
|
|
|
"""Return the PowerviewShadeData."""
|
2024-02-15 14:27:11 +00:00
|
|
|
return self.data.get_shade_position(self._shade.id)
|
2022-05-30 17:54:39 +00:00
|
|
|
|
2020-05-01 01:25:59 +00:00
|
|
|
@property
|
2021-10-22 09:52:48 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2020-05-01 01:25:59 +00:00
|
|
|
"""Return the device_info of the device."""
|
2024-02-15 14:27:11 +00:00
|
|
|
return DeviceInfo(
|
2021-10-22 09:52:48 +00:00
|
|
|
identifiers={(DOMAIN, self._shade.id)},
|
|
|
|
name=self._shade_name,
|
|
|
|
suggested_area=self._room_name,
|
|
|
|
manufacturer=MANUFACTURER,
|
2024-02-15 14:27:11 +00:00
|
|
|
model=self._shade.type_name,
|
|
|
|
sw_version=self._shade.firmware,
|
2022-06-21 16:12:11 +00:00
|
|
|
via_device=(DOMAIN, self._device_info.serial_number),
|
2024-02-15 14:27:11 +00:00
|
|
|
configuration_url=self._configuration_url,
|
2021-10-22 09:52:48 +00:00
|
|
|
)
|