2020-07-06 01:17:53 +00:00
|
|
|
"""Support for Bond covers."""
|
2021-03-17 22:34:25 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-04-30 18:38:59 +00:00
|
|
|
from typing import Any
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2021-02-09 08:43:38 +00:00
|
|
|
from bond_api import Action, BPUPSubscriptions, DeviceType
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2021-11-12 03:31:58 +00:00
|
|
|
from homeassistant.components.cover import (
|
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_CLOSE_TILT,
|
|
|
|
SUPPORT_OPEN,
|
|
|
|
SUPPORT_OPEN_TILT,
|
|
|
|
SUPPORT_STOP,
|
|
|
|
SUPPORT_STOP_TILT,
|
2021-12-09 07:26:37 +00:00
|
|
|
CoverDeviceClass,
|
2021-11-12 03:31:58 +00:00
|
|
|
CoverEntity,
|
|
|
|
)
|
2020-07-06 01:17:53 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity import Entity
|
2021-04-30 18:38:59 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2021-02-09 08:43:38 +00:00
|
|
|
from .const import BPUP_SUBS, DOMAIN, HUB
|
2020-07-11 01:20:50 +00:00
|
|
|
from .entity import BondEntity
|
2020-07-12 16:31:53 +00:00
|
|
|
from .utils import BondDevice, BondHub
|
2020-07-06 01:17:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: ConfigEntry,
|
2021-04-30 18:38:59 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2020-07-06 01:17:53 +00:00
|
|
|
) -> None:
|
|
|
|
"""Set up Bond cover devices."""
|
2021-02-09 08:43:38 +00:00
|
|
|
data = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
hub: BondHub = data[HUB]
|
|
|
|
bpup_subs: BPUPSubscriptions = data[BPUP_SUBS]
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2021-03-17 22:34:25 +00:00
|
|
|
covers: list[Entity] = [
|
2021-02-09 08:43:38 +00:00
|
|
|
BondCover(hub, device, bpup_subs)
|
2020-07-16 15:31:15 +00:00
|
|
|
for device in hub.devices
|
2020-07-23 01:22:25 +00:00
|
|
|
if device.type == DeviceType.MOTORIZED_SHADES
|
2020-07-08 21:28:53 +00:00
|
|
|
]
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2020-07-09 23:25:18 +00:00
|
|
|
async_add_entities(covers, True)
|
2020-07-06 01:17:53 +00:00
|
|
|
|
|
|
|
|
2020-07-11 01:20:50 +00:00
|
|
|
class BondCover(BondEntity, CoverEntity):
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Representation of a Bond cover."""
|
|
|
|
|
2021-12-09 07:26:37 +00:00
|
|
|
_attr_device_class = CoverDeviceClass.SHADE
|
2021-07-16 21:06:18 +00:00
|
|
|
|
2021-03-01 02:16:30 +00:00
|
|
|
def __init__(
|
|
|
|
self, hub: BondHub, device: BondDevice, bpup_subs: BPUPSubscriptions
|
|
|
|
) -> None:
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Create HA entity representing Bond cover."""
|
2021-02-09 08:43:38 +00:00
|
|
|
super().__init__(hub, device, bpup_subs)
|
2021-11-12 03:31:58 +00:00
|
|
|
supported_features = 0
|
|
|
|
if self._device.supports_open():
|
|
|
|
supported_features |= SUPPORT_OPEN
|
|
|
|
if self._device.supports_close():
|
|
|
|
supported_features |= SUPPORT_CLOSE
|
|
|
|
if self._device.supports_tilt_open():
|
|
|
|
supported_features |= SUPPORT_OPEN_TILT
|
|
|
|
if self._device.supports_tilt_close():
|
|
|
|
supported_features |= SUPPORT_CLOSE_TILT
|
|
|
|
if self._device.supports_hold():
|
|
|
|
if self._device.supports_open() or self._device.supports_close():
|
|
|
|
supported_features |= SUPPORT_STOP
|
|
|
|
if self._device.supports_tilt_open() or self._device.supports_tilt_close():
|
|
|
|
supported_features |= SUPPORT_STOP_TILT
|
|
|
|
self._attr_supported_features = supported_features
|
2020-07-11 01:20:50 +00:00
|
|
|
|
2021-03-01 02:16:30 +00:00
|
|
|
def _apply_state(self, state: dict) -> None:
|
2020-07-23 02:15:27 +00:00
|
|
|
cover_open = state.get("open")
|
2021-07-16 21:06:18 +00:00
|
|
|
self._attr_is_closed = (
|
|
|
|
True if cover_open == 0 else False if cover_open == 1 else None
|
|
|
|
)
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2020-07-23 01:22:25 +00:00
|
|
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Open the cover."""
|
2020-07-23 01:22:25 +00:00
|
|
|
await self._hub.bond.action(self._device.device_id, Action.open())
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2020-07-23 01:22:25 +00:00
|
|
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Close cover."""
|
2020-07-23 01:22:25 +00:00
|
|
|
await self._hub.bond.action(self._device.device_id, Action.close())
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2021-03-01 02:16:30 +00:00
|
|
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Hold cover."""
|
2020-07-23 01:22:25 +00:00
|
|
|
await self._hub.bond.action(self._device.device_id, Action.hold())
|
2021-11-12 03:31:58 +00:00
|
|
|
|
|
|
|
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
|
|
|
|
"""Open the cover tilt."""
|
|
|
|
await self._hub.bond.action(self._device.device_id, Action.tilt_open())
|
|
|
|
|
|
|
|
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
|
|
|
"""Close the cover tilt."""
|
|
|
|
await self._hub.bond.action(self._device.device_id, Action.tilt_close())
|
|
|
|
|
|
|
|
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
|
|
|
"""Stop the cover."""
|
|
|
|
await self._hub.bond.action(self._device.device_id, Action.hold())
|