2024-05-29 20:13:28 +00:00
|
|
|
"""Cover Entity for Genie Garage Door."""
|
2021-05-15 20:53:42 +00:00
|
|
|
|
2023-02-27 15:20:01 +00:00
|
|
|
from typing import Any
|
2018-07-30 05:19:34 +00:00
|
|
|
|
2024-06-04 08:29:51 +00:00
|
|
|
from genie_partner_sdk.model import GarageDoor
|
2018-07-30 05:19:34 +00:00
|
|
|
|
2024-06-04 08:13:31 +00:00
|
|
|
from homeassistant.components.cover import (
|
|
|
|
CoverDeviceClass,
|
|
|
|
CoverEntity,
|
|
|
|
CoverEntityFeature,
|
|
|
|
)
|
2021-05-15 20:53:42 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-07-30 05:19:34 +00:00
|
|
|
|
2024-06-04 08:51:28 +00:00
|
|
|
from . import AladdinConnectConfigEntry, AladdinConnectCoordinator
|
|
|
|
from .entity import AladdinConnectEntity
|
2018-07-30 05:19:34 +00:00
|
|
|
|
|
|
|
|
2022-05-13 22:41:01 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
2024-06-04 08:51:28 +00:00
|
|
|
config_entry: AladdinConnectConfigEntry,
|
2022-05-13 22:41:01 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up the Aladdin Connect platform."""
|
2024-06-04 08:51:28 +00:00
|
|
|
coordinator = config_entry.runtime_data
|
|
|
|
|
|
|
|
async_add_entities(AladdinDevice(coordinator, door) for door in coordinator.doors)
|
2018-07-30 05:19:34 +00:00
|
|
|
|
|
|
|
|
2024-06-04 08:51:28 +00:00
|
|
|
class AladdinDevice(AladdinConnectEntity, CoverEntity):
|
2018-07-30 05:19:34 +00:00
|
|
|
"""Representation of Aladdin Connect cover."""
|
|
|
|
|
2021-12-08 20:16:43 +00:00
|
|
|
_attr_device_class = CoverDeviceClass.GARAGE
|
2024-06-04 08:13:31 +00:00
|
|
|
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
2023-06-22 14:01:51 +00:00
|
|
|
_attr_name = None
|
2021-07-06 06:47:49 +00:00
|
|
|
|
2022-06-28 21:22:18 +00:00
|
|
|
def __init__(
|
2024-06-04 08:51:28 +00:00
|
|
|
self, coordinator: AladdinConnectCoordinator, device: GarageDoor
|
2022-06-28 21:22:18 +00:00
|
|
|
) -> None:
|
2022-05-13 22:41:01 +00:00
|
|
|
"""Initialize the Aladdin Connect cover."""
|
2024-06-04 08:51:28 +00:00
|
|
|
super().__init__(coordinator, device)
|
2024-05-29 20:13:28 +00:00
|
|
|
self._attr_unique_id = device.unique_id
|
2018-07-30 05:19:34 +00:00
|
|
|
|
2024-05-29 20:13:28 +00:00
|
|
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
|
|
|
"""Issue open command to cover."""
|
2024-06-04 08:51:28 +00:00
|
|
|
await self.coordinator.acc.open_door(
|
|
|
|
self._device.device_id, self._device.door_number
|
|
|
|
)
|
2022-06-28 21:22:18 +00:00
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
2018-07-30 05:19:34 +00:00
|
|
|
"""Issue close command to cover."""
|
2024-06-04 08:51:28 +00:00
|
|
|
await self.coordinator.acc.close_door(
|
|
|
|
self._device.device_id, self._device.door_number
|
|
|
|
)
|
2023-03-28 06:45:10 +00:00
|
|
|
|
2022-06-28 21:22:18 +00:00
|
|
|
@property
|
|
|
|
def is_closed(self) -> bool | None:
|
|
|
|
"""Update is closed attribute."""
|
2024-06-04 08:51:28 +00:00
|
|
|
value = self.coordinator.acc.get_door_status(
|
|
|
|
self._device.device_id, self._device.door_number
|
|
|
|
)
|
2022-06-28 21:22:18 +00:00
|
|
|
if value is None:
|
|
|
|
return None
|
2024-05-29 20:13:28 +00:00
|
|
|
return bool(value == "closed")
|
2022-06-28 21:22:18 +00:00
|
|
|
|
|
|
|
@property
|
2024-05-29 20:13:28 +00:00
|
|
|
def is_closing(self) -> bool | None:
|
2022-06-28 21:22:18 +00:00
|
|
|
"""Update is closing attribute."""
|
2024-06-04 08:51:28 +00:00
|
|
|
value = self.coordinator.acc.get_door_status(
|
|
|
|
self._device.device_id, self._device.door_number
|
|
|
|
)
|
2024-05-29 20:13:28 +00:00
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
return bool(value == "closing")
|
2022-06-28 21:22:18 +00:00
|
|
|
|
|
|
|
@property
|
2024-05-29 20:13:28 +00:00
|
|
|
def is_opening(self) -> bool | None:
|
2022-06-28 21:22:18 +00:00
|
|
|
"""Update is opening attribute."""
|
2024-06-04 08:51:28 +00:00
|
|
|
value = self.coordinator.acc.get_door_status(
|
|
|
|
self._device.device_id, self._device.door_number
|
|
|
|
)
|
2024-05-29 20:13:28 +00:00
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
return bool(value == "opening")
|