Strict typing Sensibo (#72454)
This commit is contained in:
parent
a4f678e7c9
commit
24c34c0ef0
15 changed files with 136 additions and 40 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pysensibo.model import MotionSensor, SensiboDevice
|
||||
|
||||
|
@ -20,6 +21,8 @@ from .const import DOMAIN
|
|||
from .coordinator import SensiboDataUpdateCoordinator
|
||||
from .entity import SensiboDeviceBaseEntity, SensiboMotionBaseEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class MotionBaseEntityDescriptionMixin:
|
||||
|
@ -93,13 +96,16 @@ async def async_setup_entry(
|
|||
coordinator: SensiboDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities: list[SensiboMotionSensor | SensiboDeviceSensor] = []
|
||||
entities.extend(
|
||||
SensiboMotionSensor(coordinator, device_id, sensor_id, sensor_data, description)
|
||||
for device_id, device_data in coordinator.data.parsed.items()
|
||||
for sensor_id, sensor_data in device_data.motion_sensors.items()
|
||||
for description in MOTION_SENSOR_TYPES
|
||||
if device_data.motion_sensors
|
||||
)
|
||||
|
||||
for device_id, device_data in coordinator.data.parsed.items():
|
||||
if device_data.motion_sensors:
|
||||
entities.extend(
|
||||
SensiboMotionSensor(
|
||||
coordinator, device_id, sensor_id, sensor_data, description
|
||||
)
|
||||
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 DEVICE_SENSOR_TYPES
|
||||
|
@ -140,6 +146,8 @@ class SensiboMotionSensor(SensiboMotionBaseEntity, BinarySensorEntity):
|
|||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
if TYPE_CHECKING:
|
||||
assert self.sensor_data
|
||||
return self.entity_description.value_fn(self.sensor_data)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue