2019-04-03 15:40:03 +00:00
|
|
|
"""Support for Gogogate2 garage Doors."""
|
2021-03-18 07:02:55 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-05-07 09:13:51 +00:00
|
|
|
from ismartgate.common import (
|
|
|
|
AbstractDoor,
|
|
|
|
DoorStatus,
|
|
|
|
TransitionDoorStatus,
|
|
|
|
get_configured_doors,
|
|
|
|
)
|
2018-04-06 13:53:00 +00:00
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
from homeassistant.components.cover import (
|
|
|
|
DEVICE_CLASS_GARAGE,
|
2020-09-06 23:55:20 +00:00
|
|
|
DEVICE_CLASS_GATE,
|
2020-05-16 15:53:11 +00:00
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_OPEN,
|
|
|
|
CoverEntity,
|
|
|
|
)
|
2021-05-09 09:46:07 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-09-05 14:26:01 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-04-30 18:38:59 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-04-06 13:53:00 +00:00
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
from .common import (
|
2020-09-05 14:26:01 +00:00
|
|
|
DeviceDataUpdateCoordinator,
|
2021-03-02 03:34:37 +00:00
|
|
|
GoGoGate2Entity,
|
2021-03-12 18:04:56 +00:00
|
|
|
cover_unique_id,
|
2020-05-16 15:53:11 +00:00
|
|
|
get_data_update_coordinator,
|
|
|
|
)
|
2021-03-12 12:52:46 +00:00
|
|
|
|
2018-04-06 13:53:00 +00:00
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
2021-04-30 18:38:59 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2020-05-16 15:53:11 +00:00
|
|
|
) -> None:
|
|
|
|
"""Set up the config entry."""
|
|
|
|
data_update_coordinator = get_data_update_coordinator(hass, config_entry)
|
|
|
|
|
|
|
|
async_add_entities(
|
|
|
|
[
|
2020-09-05 14:26:01 +00:00
|
|
|
DeviceCover(config_entry, data_update_coordinator, door)
|
2020-05-16 15:53:11 +00:00
|
|
|
for door in get_configured_doors(data_update_coordinator.data)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-03-02 03:34:37 +00:00
|
|
|
class DeviceCover(GoGoGate2Entity, CoverEntity):
|
2020-05-16 15:53:11 +00:00
|
|
|
"""Cover entity for goggate2."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
config_entry: ConfigEntry,
|
2020-09-05 14:26:01 +00:00
|
|
|
data_update_coordinator: DeviceDataUpdateCoordinator,
|
|
|
|
door: AbstractDoor,
|
2020-05-16 15:53:11 +00:00
|
|
|
) -> None:
|
|
|
|
"""Initialize the object."""
|
2021-03-12 18:04:56 +00:00
|
|
|
unique_id = cover_unique_id(config_entry, door)
|
|
|
|
super().__init__(config_entry, data_update_coordinator, door, unique_id)
|
2020-05-16 15:53:11 +00:00
|
|
|
self._api = data_update_coordinator.api
|
|
|
|
self._is_available = True
|
2018-04-06 13:53:00 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-05-16 15:53:11 +00:00
|
|
|
"""Return the name of the door."""
|
2020-09-05 14:26:01 +00:00
|
|
|
return self._get_door().name
|
2018-04-06 13:53:00 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return true if cover is closed, else False."""
|
2021-05-07 09:13:51 +00:00
|
|
|
door_status = self._get_door_status()
|
|
|
|
if door_status == DoorStatus.OPENED:
|
2020-05-16 15:53:11 +00:00
|
|
|
return False
|
2021-05-07 09:13:51 +00:00
|
|
|
if door_status == DoorStatus.CLOSED:
|
2020-05-16 15:53:11 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-04-06 13:53:00 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
2021-05-07 09:13:51 +00:00
|
|
|
if self._get_door().gate:
|
2020-09-06 23:55:20 +00:00
|
|
|
return DEVICE_CLASS_GATE
|
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
return DEVICE_CLASS_GARAGE
|
2018-04-06 13:53:00 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_OPEN | SUPPORT_CLOSE
|
|
|
|
|
2021-05-07 09:13:51 +00:00
|
|
|
@property
|
|
|
|
def is_closing(self):
|
|
|
|
"""Return if the cover is closing or not."""
|
|
|
|
return self._get_door_status() == TransitionDoorStatus.CLOSING
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_opening(self):
|
|
|
|
"""Return if the cover is opening or not."""
|
|
|
|
return self._get_door_status() == TransitionDoorStatus.OPENING
|
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
async def async_open_cover(self, **kwargs):
|
|
|
|
"""Open the door."""
|
2021-01-17 17:38:30 +00:00
|
|
|
await self._api.async_open_door(self._get_door().door_id)
|
2021-05-07 09:13:51 +00:00
|
|
|
await self.coordinator.async_refresh()
|
2020-05-16 15:53:11 +00:00
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
|
|
"""Close the door."""
|
2021-01-17 17:38:30 +00:00
|
|
|
await self._api.async_close_door(self._get_door().door_id)
|
2021-05-07 09:13:51 +00:00
|
|
|
await self.coordinator.async_refresh()
|
2020-05-16 15:53:11 +00:00
|
|
|
|
2018-04-06 13:53:00 +00:00
|
|
|
@property
|
2021-03-11 15:57:47 +00:00
|
|
|
def extra_state_attributes(self):
|
2020-05-16 15:53:11 +00:00
|
|
|
"""Return the state attributes."""
|
2021-03-03 09:20:48 +00:00
|
|
|
return {"door_id": self._get_door().door_id}
|
2021-05-07 09:13:51 +00:00
|
|
|
|
|
|
|
def _get_door_status(self) -> AbstractDoor:
|
|
|
|
return self._api.async_get_door_statuses_from_info(self.coordinator.data)[
|
|
|
|
self._door.door_id
|
|
|
|
]
|