75 lines
2.1 KiB
Python
75 lines
2.1 KiB
Python
"""Binary sensors for Sternwarte."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DOMAIN, ENTITY_RAIN, ENTITY_ROOF_CLOSED, ENTITY_ROOF_MOVING, ENTITY_ROOF_OPEN
|
|
from .entity import SternwarteEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up Sternwarte binary sensors."""
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities(
|
|
[
|
|
SternwarteClosedSensor(coordinator),
|
|
SternwarteOpenSensor(coordinator),
|
|
SternwarteMovingSensor(coordinator),
|
|
SternwarteRainSensor(coordinator),
|
|
]
|
|
)
|
|
|
|
|
|
class SternwarteClosedSensor(SternwarteEntity, BinarySensorEntity):
|
|
_attr_name = "Dach zu"
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_ROOF_CLOSED)
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.coordinator.data.roof_closed
|
|
|
|
|
|
class SternwarteOpenSensor(SternwarteEntity, BinarySensorEntity):
|
|
_attr_name = "Dach offen"
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_ROOF_OPEN)
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.coordinator.data.roof_open
|
|
|
|
|
|
class SternwarteMovingSensor(SternwarteEntity, BinarySensorEntity):
|
|
_attr_name = "Dach bewegt"
|
|
_attr_device_class = BinarySensorDeviceClass.MOVING
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_ROOF_MOVING)
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.coordinator.data.roof_moving
|
|
|
|
|
|
class SternwarteRainSensor(SternwarteEntity, BinarySensorEntity):
|
|
_attr_name = "Regen"
|
|
_attr_device_class = BinarySensorDeviceClass.MOISTURE
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_RAIN)
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.coordinator.data.raining
|