Sensibo Add timer (#73072)
This commit is contained in:
parent
dca4d3cd61
commit
c660fae8d8
6 changed files with 373 additions and 15 deletions
|
@ -1,9 +1,9 @@
|
|||
"""Binary Sensor platform for Sensibo integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pysensibo.model import MotionSensor, SensiboDevice
|
||||
|
||||
|
@ -36,6 +36,7 @@ class DeviceBaseEntityDescriptionMixin:
|
|||
"""Mixin for required Sensibo base description keys."""
|
||||
|
||||
value_fn: Callable[[SensiboDevice], bool | None]
|
||||
extra_fn: Callable[[SensiboDevice], dict[str, str | bool | None] | None] | None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -77,13 +78,25 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionBinarySensorEntityDescription, ...] = (
|
|||
),
|
||||
)
|
||||
|
||||
DEVICE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
||||
MOTION_DEVICE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="room_occupied",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
name="Room Occupied",
|
||||
icon="mdi:motion-sensor",
|
||||
value_fn=lambda data: data.room_occupied,
|
||||
extra_fn=None,
|
||||
),
|
||||
)
|
||||
|
||||
DEVICE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="timer_on",
|
||||
device_class=BinarySensorDeviceClass.RUNNING,
|
||||
name="Timer Running",
|
||||
icon="mdi:timer",
|
||||
value_fn=lambda data: data.timer_on,
|
||||
extra_fn=lambda data: {"id": data.timer_id, "turn_on": data.timer_state_on},
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -94,6 +107,7 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
|||
name="Pure Boost Enabled",
|
||||
icon="mdi:wind-power-outline",
|
||||
value_fn=lambda data: data.pure_boost_enabled,
|
||||
extra_fn=None,
|
||||
),
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="pure_ac_integration",
|
||||
|
@ -102,6 +116,7 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
|||
name="Pure Boost linked with AC",
|
||||
icon="mdi:connection",
|
||||
value_fn=lambda data: data.pure_ac_integration,
|
||||
extra_fn=None,
|
||||
),
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="pure_geo_integration",
|
||||
|
@ -110,6 +125,7 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
|||
name="Pure Boost linked with Presence",
|
||||
icon="mdi:connection",
|
||||
value_fn=lambda data: data.pure_geo_integration,
|
||||
extra_fn=None,
|
||||
),
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="pure_measure_integration",
|
||||
|
@ -118,6 +134,7 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
|||
name="Pure Boost linked with Indoor Air Quality",
|
||||
icon="mdi:connection",
|
||||
value_fn=lambda data: data.pure_measure_integration,
|
||||
extra_fn=None,
|
||||
),
|
||||
SensiboDeviceBinarySensorEntityDescription(
|
||||
key="pure_prime_integration",
|
||||
|
@ -126,6 +143,7 @@ PURE_SENSOR_TYPES: tuple[SensiboDeviceBinarySensorEntityDescription, ...] = (
|
|||
name="Pure Boost linked with Outdoor Air Quality",
|
||||
icon="mdi:connection",
|
||||
value_fn=lambda data: data.pure_prime_integration,
|
||||
extra_fn=None,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -148,11 +166,17 @@ async def async_setup_entry(
|
|||
for sensor_id, sensor_data in device_data.motion_sensors.items()
|
||||
for description in MOTION_SENSOR_TYPES
|
||||
)
|
||||
entities.extend(
|
||||
SensiboDeviceSensor(coordinator, device_id, description)
|
||||
for description in MOTION_DEVICE_SENSOR_TYPES
|
||||
for device_id, device_data in coordinator.data.parsed.items()
|
||||
if device_data.motion_sensors is not None
|
||||
)
|
||||
entities.extend(
|
||||
SensiboDeviceSensor(coordinator, device_id, description)
|
||||
for description in DEVICE_SENSOR_TYPES
|
||||
for device_id, device_data in coordinator.data.parsed.items()
|
||||
if getattr(device_data, description.key) is not None
|
||||
if device_data.model != "pure"
|
||||
)
|
||||
entities.extend(
|
||||
SensiboDeviceSensor(coordinator, device_id, description)
|
||||
|
@ -223,3 +247,10 @@ class SensiboDeviceSensor(SensiboDeviceBaseEntity, BinarySensorEntity):
|
|||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self.entity_description.value_fn(self.device_data)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
||||
"""Return additional attributes."""
|
||||
if self.entity_description.extra_fn is not None:
|
||||
return self.entity_description.extra_fn(self.device_data)
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue