mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add binary sensors for motion detection Comelit simple home (#125200)
* Add binary sensors for motion detection * sort platforms * use _attr_device_class property and optimizations * use static _attr_device_class property
This commit is contained in:
parent
543f986955
commit
2c99f060f0
@ -19,6 +19,7 @@ BRIDGE_PLATFORMS = [
|
|||||||
]
|
]
|
||||||
VEDO_PLATFORMS = [
|
VEDO_PLATFORMS = [
|
||||||
Platform.ALARM_CONTROL_PANEL,
|
Platform.ALARM_CONTROL_PANEL,
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
62
homeassistant/components/comelit/binary_sensor.py
Normal file
62
homeassistant/components/comelit/binary_sensor.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
"""Support for sensors."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from aiocomelit import ComelitVedoZoneObject
|
||||||
|
from aiocomelit.const import ALARM_ZONES
|
||||||
|
|
||||||
|
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 homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import ComelitVedoSystem
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up Comelit VEDO presence sensors."""
|
||||||
|
|
||||||
|
coordinator: ComelitVedoSystem = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
ComelitVedoBinarySensorEntity(coordinator, device, config_entry.entry_id)
|
||||||
|
for device in coordinator.data[ALARM_ZONES].values()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ComelitVedoBinarySensorEntity(
|
||||||
|
CoordinatorEntity[ComelitVedoSystem], BinarySensorEntity
|
||||||
|
):
|
||||||
|
"""Sensor device."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_device_class = BinarySensorDeviceClass.MOTION
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: ComelitVedoSystem,
|
||||||
|
zone: ComelitVedoZoneObject,
|
||||||
|
config_entry_entry_id: str,
|
||||||
|
) -> None:
|
||||||
|
"""Init sensor entity."""
|
||||||
|
self._api = coordinator.api
|
||||||
|
self._zone = zone
|
||||||
|
super().__init__(coordinator)
|
||||||
|
# Use config_entry.entry_id as base for unique_id
|
||||||
|
# because no serial number or mac is available
|
||||||
|
self._attr_unique_id = f"{config_entry_entry_id}-presence-{zone.index}"
|
||||||
|
self._attr_device_info = coordinator.platform_device_info(zone, "zone")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Presence detected."""
|
||||||
|
return self.coordinator.data[ALARM_ZONES][self._zone.index].status_api == "0001"
|
Loading…
x
Reference in New Issue
Block a user