Complete typing of some platforms of deCONZ integration (#67494)
This commit is contained in:
parent
2a538f6ae1
commit
bff91b170f
5 changed files with 31 additions and 26 deletions
|
@ -70,7 +70,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Alarm: [
|
Alarm: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="alarm",
|
key="alarm",
|
||||||
value_fn=lambda device: device.alarm,
|
value_fn=lambda device: device.alarm, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="alarm",
|
update_key="alarm",
|
||||||
device_class=BinarySensorDeviceClass.SAFETY,
|
device_class=BinarySensorDeviceClass.SAFETY,
|
||||||
|
@ -79,7 +79,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
CarbonMonoxide: [
|
CarbonMonoxide: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="carbon_monoxide",
|
key="carbon_monoxide",
|
||||||
value_fn=lambda device: device.carbon_monoxide,
|
value_fn=lambda device: device.carbon_monoxide, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="carbonmonoxide",
|
update_key="carbonmonoxide",
|
||||||
device_class=BinarySensorDeviceClass.CO,
|
device_class=BinarySensorDeviceClass.CO,
|
||||||
|
@ -88,14 +88,14 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Fire: [
|
Fire: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="fire",
|
key="fire",
|
||||||
value_fn=lambda device: device.fire,
|
value_fn=lambda device: device.fire, # type: ignore[no-any-return]
|
||||||
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,
|
value_fn=lambda device: device.in_test_mode, # type: ignore[no-any-return]
|
||||||
suffix="Test Mode",
|
suffix="Test Mode",
|
||||||
update_key="test",
|
update_key="test",
|
||||||
device_class=BinarySensorDeviceClass.SMOKE,
|
device_class=BinarySensorDeviceClass.SMOKE,
|
||||||
|
@ -105,7 +105,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
GenericFlag: [
|
GenericFlag: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="flag",
|
key="flag",
|
||||||
value_fn=lambda device: device.flag,
|
value_fn=lambda device: device.flag, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="flag",
|
update_key="flag",
|
||||||
)
|
)
|
||||||
|
@ -113,7 +113,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
OpenClose: [
|
OpenClose: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="open",
|
key="open",
|
||||||
value_fn=lambda device: device.open,
|
value_fn=lambda device: device.open, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="open",
|
update_key="open",
|
||||||
device_class=BinarySensorDeviceClass.OPENING,
|
device_class=BinarySensorDeviceClass.OPENING,
|
||||||
|
@ -122,7 +122,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Presence: [
|
Presence: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="presence",
|
key="presence",
|
||||||
value_fn=lambda device: device.presence,
|
value_fn=lambda device: device.presence, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="presence",
|
update_key="presence",
|
||||||
device_class=BinarySensorDeviceClass.MOTION,
|
device_class=BinarySensorDeviceClass.MOTION,
|
||||||
|
@ -131,7 +131,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Vibration: [
|
Vibration: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="vibration",
|
key="vibration",
|
||||||
value_fn=lambda device: device.vibration,
|
value_fn=lambda device: device.vibration, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="vibration",
|
update_key="vibration",
|
||||||
device_class=BinarySensorDeviceClass.VIBRATION,
|
device_class=BinarySensorDeviceClass.VIBRATION,
|
||||||
|
@ -140,7 +140,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Water: [
|
Water: [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="water",
|
key="water",
|
||||||
value_fn=lambda device: device.water,
|
value_fn=lambda device: device.water, # type: ignore[no-any-return]
|
||||||
suffix="",
|
suffix="",
|
||||||
update_key="water",
|
update_key="water",
|
||||||
device_class=BinarySensorDeviceClass.MOISTURE,
|
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||||
|
@ -151,7 +151,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
BINARY_SENSOR_DESCRIPTIONS = [
|
BINARY_SENSOR_DESCRIPTIONS = [
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="tampered",
|
key="tampered",
|
||||||
value_fn=lambda device: device.tampered,
|
value_fn=lambda device: device.tampered, # type: ignore[no-any-return]
|
||||||
suffix="Tampered",
|
suffix="Tampered",
|
||||||
update_key="tampered",
|
update_key="tampered",
|
||||||
device_class=BinarySensorDeviceClass.TAMPER,
|
device_class=BinarySensorDeviceClass.TAMPER,
|
||||||
|
@ -159,7 +159,7 @@ BINARY_SENSOR_DESCRIPTIONS = [
|
||||||
),
|
),
|
||||||
DeconzBinarySensorDescription(
|
DeconzBinarySensorDescription(
|
||||||
key="low_battery",
|
key="low_battery",
|
||||||
value_fn=lambda device: device.low_battery,
|
value_fn=lambda device: device.low_battery, # type: ignore[no-any-return]
|
||||||
suffix="Low Battery",
|
suffix="Low Battery",
|
||||||
update_key="lowbattery",
|
update_key="lowbattery",
|
||||||
device_class=BinarySensorDeviceClass.BATTERY,
|
device_class=BinarySensorDeviceClass.BATTERY,
|
||||||
|
@ -266,11 +266,11 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, bool | float | int | list | None]:
|
def extra_state_attributes(self) -> dict[str, bool | float | int | list | None]:
|
||||||
"""Return the state attributes of the sensor."""
|
"""Return the state attributes of the sensor."""
|
||||||
if self.entity_description.key not in PROVIDES_EXTRA_ATTRIBUTES:
|
|
||||||
return
|
|
||||||
|
|
||||||
attr: dict[str, bool | float | int | list | None] = {}
|
attr: dict[str, bool | float | int | list | None] = {}
|
||||||
|
|
||||||
|
if self.entity_description.key not in PROVIDES_EXTRA_ATTRIBUTES:
|
||||||
|
return attr
|
||||||
|
|
||||||
if self._device.on is not None:
|
if self._device.on is not None:
|
||||||
attr[ATTR_ON] = self._device.on
|
attr[ATTR_ON] = self._device.on
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import ValuesView
|
from collections.abc import ValuesView
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
|
|
||||||
from pydeconz.group import Group
|
from pydeconz.group import Group
|
||||||
from pydeconz.light import (
|
from pydeconz.light import (
|
||||||
|
@ -220,11 +220,15 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
||||||
elif "IKEA" in self._device.manufacturer:
|
elif "IKEA" in self._device.manufacturer:
|
||||||
data["transition_time"] = 0
|
data["transition_time"] = 0
|
||||||
|
|
||||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
if (
|
||||||
|
alert := FLASH_TO_DECONZ.get(cast(str, kwargs.get(ATTR_FLASH)))
|
||||||
|
) is not None:
|
||||||
data["alert"] = alert
|
data["alert"] = alert
|
||||||
del data["on"]
|
del data["on"]
|
||||||
|
|
||||||
if (effect := EFFECT_TO_DECONZ.get(kwargs.get(ATTR_EFFECT))) is not None:
|
if (
|
||||||
|
effect := EFFECT_TO_DECONZ.get(cast(str, kwargs.get(ATTR_EFFECT)))
|
||||||
|
) is not None:
|
||||||
data["effect"] = effect
|
data["effect"] = effect
|
||||||
|
|
||||||
await self._device.set_state(**data)
|
await self._device.set_state(**data)
|
||||||
|
@ -240,7 +244,9 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
||||||
data["brightness"] = 0
|
data["brightness"] = 0
|
||||||
data["transition_time"] = int(attr_transition * 10)
|
data["transition_time"] = int(attr_transition * 10)
|
||||||
|
|
||||||
if (alert := FLASH_TO_DECONZ.get(kwargs.get(ATTR_FLASH))) is not None:
|
if (
|
||||||
|
alert := FLASH_TO_DECONZ.get(cast(str, kwargs.get(ATTR_FLASH)))
|
||||||
|
) is not None:
|
||||||
data["alert"] = alert
|
data["alert"] = alert
|
||||||
del data["on"]
|
del data["on"]
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@ from __future__ import annotations
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from homeassistant.const import ATTR_DEVICE_ID, CONF_EVENT
|
from homeassistant.const import ATTR_DEVICE_ID, CONF_EVENT
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
import homeassistant.helpers.device_registry as dr
|
import homeassistant.helpers.device_registry as dr
|
||||||
from homeassistant.helpers.event import Event
|
|
||||||
|
|
||||||
from .const import CONF_GESTURE, DOMAIN as DECONZ_DOMAIN
|
from .const import CONF_GESTURE, DOMAIN as DECONZ_DOMAIN
|
||||||
from .deconz_event import CONF_DECONZ_ALARM_EVENT, CONF_DECONZ_EVENT
|
from .deconz_event import CONF_DECONZ_ALARM_EVENT, CONF_DECONZ_EVENT
|
||||||
|
|
|
@ -28,7 +28,7 @@ class DeconzNumberDescriptionMixin:
|
||||||
|
|
||||||
suffix: str
|
suffix: str
|
||||||
update_key: str
|
update_key: str
|
||||||
value_fn: Callable[[PydeconzSensor], bool | None]
|
value_fn: Callable[[PydeconzSensor], float | None]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -40,7 +40,7 @@ ENTITY_DESCRIPTIONS = {
|
||||||
Presence: [
|
Presence: [
|
||||||
DeconzNumberDescription(
|
DeconzNumberDescription(
|
||||||
key="delay",
|
key="delay",
|
||||||
value_fn=lambda device: device.delay,
|
value_fn=lambda device: device.delay, # type: ignore[no-any-return]
|
||||||
suffix="Delay",
|
suffix="Delay",
|
||||||
update_key=PRESENCE_DELAY,
|
update_key=PRESENCE_DELAY,
|
||||||
max_value=65535,
|
max_value=65535,
|
||||||
|
|
|
@ -75,7 +75,7 @@ class DeconzSensorDescriptionMixin:
|
||||||
"""Required values when describing secondary sensor attributes."""
|
"""Required values when describing secondary sensor attributes."""
|
||||||
|
|
||||||
update_key: str
|
update_key: str
|
||||||
value_fn: Callable[[PydeconzSensor], float | int | None]
|
value_fn: Callable[[PydeconzSensor], float | int | str | None]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -334,14 +334,14 @@ class DeconzSensor(DeconzDevice, SensorEntity):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self.entity_description.device_class is SensorDeviceClass.TIMESTAMP:
|
if self.entity_description.device_class is SensorDeviceClass.TIMESTAMP:
|
||||||
return dt_util.parse_datetime(
|
return dt_util.parse_datetime(
|
||||||
self.entity_description.value_fn(self._device)
|
self.entity_description.value_fn(self._device) # type: ignore[arg-type]
|
||||||
)
|
)
|
||||||
return self.entity_description.value_fn(self._device)
|
return self.entity_description.value_fn(self._device)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, bool | float | int | None]:
|
def extra_state_attributes(self) -> dict[str, bool | float | int | str | None]:
|
||||||
"""Return the state attributes of the sensor."""
|
"""Return the state attributes of the sensor."""
|
||||||
attr: dict[str, bool | float | int | None] = {}
|
attr: dict[str, bool | float | int | str | None] = {}
|
||||||
|
|
||||||
if self.entity_description.key not in PROVIDES_EXTRA_ATTRIBUTES:
|
if self.entity_description.key not in PROVIDES_EXTRA_ATTRIBUTES:
|
||||||
return attr
|
return attr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue