Improve typing of deCONZ binary_sensor platform (#70003)
This commit is contained in:
parent
d704d4f853
commit
5258022e45
1 changed files with 26 additions and 14 deletions
|
@ -11,7 +11,7 @@ from pydeconz.sensor import (
|
||||||
GenericFlag,
|
GenericFlag,
|
||||||
OpenClose,
|
OpenClose,
|
||||||
Presence,
|
Presence,
|
||||||
SensorBase as PydeconzSensor,
|
SensorResources,
|
||||||
Vibration,
|
Vibration,
|
||||||
Water,
|
Water,
|
||||||
)
|
)
|
||||||
|
@ -55,7 +55,7 @@ class DeconzBinarySensorDescriptionMixin:
|
||||||
|
|
||||||
suffix: str
|
suffix: str
|
||||||
update_key: str
|
update_key: str
|
||||||
value_fn: Callable[[PydeconzSensor], bool | None]
|
value_fn: Callable[[SensorResources], bool | None]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -70,7 +70,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Alarm: [
|
Alarm: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="alarm",
|
key="alarm",
|
||||||
value_fn=lambda device: device.alarm, # type: ignore[no-any-return]
|
value_fn=lambda device: device.alarm if isinstance(device, Alarm) else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="alarm",
|
update_key="alarm",
|
||||||
device_class=BinarySensorDeviceClass.SAFETY,
|
device_class=BinarySensorDeviceClass.SAFETY,
|
||||||
|
@ -79,7 +79,9 @@ ENTITY_DESCRIPTIONS = {
|
||||||
CarbonMonoxide: [
|
CarbonMonoxide: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="carbon_monoxide",
|
key="carbon_monoxide",
|
||||||
value_fn=lambda device: device.carbon_monoxide, # type: ignore[no-any-return]
|
value_fn=lambda device: device.carbon_monoxide
|
||||||
|
if isinstance(device, CarbonMonoxide)
|
||||||
|
else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="carbonmonoxide",
|
update_key="carbonmonoxide",
|
||||||
device_class=BinarySensorDeviceClass.CO,
|
device_class=BinarySensorDeviceClass.CO,
|
||||||
|
@ -88,14 +90,16 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Fire: [
|
Fire: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="fire",
|
key="fire",
|
||||||
value_fn=lambda device: device.fire, # type: ignore[no-any-return]
|
value_fn=lambda device: device.fire if isinstance(device, Fire) else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="fire",
|
update_key="fire",
|
||||||
device_class=BinarySensorDeviceClass.SMOKE,
|
device_class=BinarySensorDeviceClass.SMOKE,
|
||||||
),
|
),
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="in_test_mode",
|
key="in_test_mode",
|
||||||
value_fn=lambda device: device.in_test_mode, # type: ignore[no-any-return]
|
value_fn=lambda device: device.in_test_mode
|
||||||
|
if isinstance(device, Fire)
|
||||||
|
else None,
|
||||||
suffix="Test Mode",
|
suffix="Test Mode",
|
||||||
update_key="test",
|
update_key="test",
|
||||||
device_class=BinarySensorDeviceClass.SMOKE,
|
device_class=BinarySensorDeviceClass.SMOKE,
|
||||||
|
@ -105,7 +109,9 @@ ENTITY_DESCRIPTIONS = {
|
||||||
GenericFlag: [
|
GenericFlag: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="flag",
|
key="flag",
|
||||||
value_fn=lambda device: device.flag, # type: ignore[no-any-return]
|
value_fn=lambda device: device.flag
|
||||||
|
if isinstance(device, GenericFlag)
|
||||||
|
else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="flag",
|
update_key="flag",
|
||||||
)
|
)
|
||||||
|
@ -113,7 +119,9 @@ ENTITY_DESCRIPTIONS = {
|
||||||
OpenClose: [
|
OpenClose: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="open",
|
key="open",
|
||||||
value_fn=lambda device: device.open, # type: ignore[no-any-return]
|
value_fn=lambda device: device.open
|
||||||
|
if isinstance(device, OpenClose)
|
||||||
|
else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="open",
|
update_key="open",
|
||||||
device_class=BinarySensorDeviceClass.OPENING,
|
device_class=BinarySensorDeviceClass.OPENING,
|
||||||
|
@ -122,7 +130,9 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Presence: [
|
Presence: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="presence",
|
key="presence",
|
||||||
value_fn=lambda device: device.presence, # type: ignore[no-any-return]
|
value_fn=lambda device: device.presence
|
||||||
|
if isinstance(device, Presence)
|
||||||
|
else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="presence",
|
update_key="presence",
|
||||||
device_class=BinarySensorDeviceClass.MOTION,
|
device_class=BinarySensorDeviceClass.MOTION,
|
||||||
|
@ -131,7 +141,9 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Vibration: [
|
Vibration: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="vibration",
|
key="vibration",
|
||||||
value_fn=lambda device: device.vibration, # type: ignore[no-any-return]
|
value_fn=lambda device: device.vibration
|
||||||
|
if isinstance(device, Vibration)
|
||||||
|
else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="vibration",
|
update_key="vibration",
|
||||||
device_class=BinarySensorDeviceClass.VIBRATION,
|
device_class=BinarySensorDeviceClass.VIBRATION,
|
||||||
|
@ -140,7 +152,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Water: [
|
Water: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="water",
|
key="water",
|
||||||
value_fn=lambda device: device.water, # type: ignore[no-any-return]
|
value_fn=lambda device: device.water if isinstance(device, Water) else None,
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="water",
|
update_key="water",
|
||||||
device_class=BinarySensorDeviceClass.MOISTURE,
|
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||||
|
@ -178,7 +190,7 @@ async def async_setup_entry(
|
||||||
gateway.entities[DOMAIN] = set()
|
gateway.entities[DOMAIN] = set()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_sensor(sensors: list[PydeconzSensor] | None = None) -> None:
|
def async_add_sensor(sensors: list[SensorResources] | None = None) -> None:
|
||||||
"""Add binary sensor from deCONZ."""
|
"""Add binary sensor from deCONZ."""
|
||||||
entities: list[DeconzBinarySensor] = []
|
entities: list[DeconzBinarySensor] = []
|
||||||
|
|
||||||
|
@ -225,12 +237,12 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
|
||||||
"""Representation of a deCONZ binary sensor."""
|
"""Representation of a deCONZ binary sensor."""
|
||||||
|
|
||||||
TYPE = DOMAIN
|
TYPE = DOMAIN
|
||||||
_device: PydeconzSensor
|
_device: SensorResources
|
||||||
entity_description: DeconzBinarySensorDescription
|
entity_description: DeconzBinarySensorDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
device: PydeconzSensor,
|
device: SensorResources,
|
||||||
gateway: DeconzGateway,
|
gateway: DeconzGateway,
|
||||||
description: DeconzBinarySensorDescription,
|
description: DeconzBinarySensorDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue