2020-03-31 18:58:44 +00:00
|
|
|
"""Support for MyQ gateways."""
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-15 19:44:27 +00:00
|
|
|
BinarySensorDeviceClass,
|
2020-04-23 19:57:07 +00:00
|
|
|
BinarySensorEntity,
|
2020-03-31 18:58:44 +00:00
|
|
|
)
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-12-15 19:44:27 +00:00
|
|
|
from homeassistant.helpers.entity import EntityCategory
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-03-31 18:58:44 +00:00
|
|
|
|
2021-08-19 01:50:46 +00:00
|
|
|
from . import MyQEntity
|
2020-05-10 18:42:28 +00:00
|
|
|
from .const import DOMAIN, MYQ_COORDINATOR, MYQ_GATEWAY
|
2020-03-31 18:58:44 +00:00
|
|
|
|
|
|
|
|
2022-01-03 10:32:26 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-03-31 18:58:44 +00:00
|
|
|
"""Set up mysq covers."""
|
|
|
|
data = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
myq = data[MYQ_GATEWAY]
|
|
|
|
coordinator = data[MYQ_COORDINATOR]
|
|
|
|
|
|
|
|
entities = []
|
|
|
|
|
2021-02-10 20:30:52 +00:00
|
|
|
for device in myq.gateways.values():
|
|
|
|
entities.append(MyQBinarySensorEntity(coordinator, device))
|
2020-03-31 18:58:44 +00:00
|
|
|
|
2021-05-03 04:52:48 +00:00
|
|
|
async_add_entities(entities)
|
2020-03-31 18:58:44 +00:00
|
|
|
|
|
|
|
|
2021-08-19 01:50:46 +00:00
|
|
|
class MyQBinarySensorEntity(MyQEntity, BinarySensorEntity):
|
2020-03-31 18:58:44 +00:00
|
|
|
"""Representation of a MyQ gateway."""
|
|
|
|
|
2021-12-15 19:44:27 +00:00
|
|
|
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
|
|
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
2021-06-01 19:43:55 +00:00
|
|
|
|
2020-03-31 18:58:44 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the garage door if any."""
|
|
|
|
return f"{self._device.name} MyQ Gateway"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return if the device is online."""
|
2021-08-19 01:50:46 +00:00
|
|
|
return super().available
|
2020-03-31 18:58:44 +00:00
|
|
|
|
2020-08-30 12:40:00 +00:00
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Entity is always available."""
|
|
|
|
return True
|