mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Complete typing of some platforms of deCONZ integration (#67494)
This commit is contained in:
parent
2a538f6ae1
commit
bff91b170f
@ -70,7 +70,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
Alarm: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="alarm",
|
||||
value_fn=lambda device: device.alarm,
|
||||
value_fn=lambda device: device.alarm, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="alarm",
|
||||
device_class=BinarySensorDeviceClass.SAFETY,
|
||||
@ -79,7 +79,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
CarbonMonoxide: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="carbon_monoxide",
|
||||
value_fn=lambda device: device.carbon_monoxide,
|
||||
value_fn=lambda device: device.carbon_monoxide, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="carbonmonoxide",
|
||||
device_class=BinarySensorDeviceClass.CO,
|
||||
@ -88,14 +88,14 @@ ENTITY_DESCRIPTIONS = {
|
||||
Fire: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="fire",
|
||||
value_fn=lambda device: device.fire,
|
||||
value_fn=lambda device: device.fire, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="fire",
|
||||
device_class=BinarySensorDeviceClass.SMOKE,
|
||||
),
|
||||
DeconzBinarySensorDescription(
|
||||
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",
|
||||
update_key="test",
|
||||
device_class=BinarySensorDeviceClass.SMOKE,
|
||||
@ -105,7 +105,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
GenericFlag: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="flag",
|
||||
value_fn=lambda device: device.flag,
|
||||
value_fn=lambda device: device.flag, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="flag",
|
||||
)
|
||||
@ -113,7 +113,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
OpenClose: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="open",
|
||||
value_fn=lambda device: device.open,
|
||||
value_fn=lambda device: device.open, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="open",
|
||||
device_class=BinarySensorDeviceClass.OPENING,
|
||||
@ -122,7 +122,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
Presence: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="presence",
|
||||
value_fn=lambda device: device.presence,
|
||||
value_fn=lambda device: device.presence, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="presence",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
@ -131,7 +131,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
Vibration: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="vibration",
|
||||
value_fn=lambda device: device.vibration,
|
||||
value_fn=lambda device: device.vibration, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="vibration",
|
||||
device_class=BinarySensorDeviceClass.VIBRATION,
|
||||
@ -140,7 +140,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
Water: [
|
||||
DeconzBinarySensorDescription(
|
||||
key="water",
|
||||
value_fn=lambda device: device.water,
|
||||
value_fn=lambda device: device.water, # type: ignore[no-any-return]
|
||||
suffix="",
|
||||
update_key="water",
|
||||
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||
@ -151,7 +151,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
BINARY_SENSOR_DESCRIPTIONS = [
|
||||
DeconzBinarySensorDescription(
|
||||
key="tampered",
|
||||
value_fn=lambda device: device.tampered,
|
||||
value_fn=lambda device: device.tampered, # type: ignore[no-any-return]
|
||||
suffix="Tampered",
|
||||
update_key="tampered",
|
||||
device_class=BinarySensorDeviceClass.TAMPER,
|
||||
@ -159,7 +159,7 @@ BINARY_SENSOR_DESCRIPTIONS = [
|
||||
),
|
||||
DeconzBinarySensorDescription(
|
||||
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",
|
||||
update_key="lowbattery",
|
||||
device_class=BinarySensorDeviceClass.BATTERY,
|
||||
@ -266,11 +266,11 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, bool | float | int | list | None]:
|
||||
"""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] = {}
|
||||
|
||||
if self.entity_description.key not in PROVIDES_EXTRA_ATTRIBUTES:
|
||||
return attr
|
||||
|
||||
if self._device.on is not None:
|
||||
attr[ATTR_ON] = self._device.on
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import ValuesView
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from pydeconz.group import Group
|
||||
from pydeconz.light import (
|
||||
@ -220,11 +220,15 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
||||
elif "IKEA" in self._device.manufacturer:
|
||||
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
|
||||
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
|
||||
|
||||
await self._device.set_state(**data)
|
||||
@ -240,7 +244,9 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
||||
data["brightness"] = 0
|
||||
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
|
||||
del data["on"]
|
||||
|
||||
|
@ -4,9 +4,8 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
|
||||
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
|
||||
from homeassistant.helpers.event import Event
|
||||
|
||||
from .const import CONF_GESTURE, DOMAIN as DECONZ_DOMAIN
|
||||
from .deconz_event import CONF_DECONZ_ALARM_EVENT, CONF_DECONZ_EVENT
|
||||
|
@ -28,7 +28,7 @@ class DeconzNumberDescriptionMixin:
|
||||
|
||||
suffix: str
|
||||
update_key: str
|
||||
value_fn: Callable[[PydeconzSensor], bool | None]
|
||||
value_fn: Callable[[PydeconzSensor], float | None]
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -40,7 +40,7 @@ ENTITY_DESCRIPTIONS = {
|
||||
Presence: [
|
||||
DeconzNumberDescription(
|
||||
key="delay",
|
||||
value_fn=lambda device: device.delay,
|
||||
value_fn=lambda device: device.delay, # type: ignore[no-any-return]
|
||||
suffix="Delay",
|
||||
update_key=PRESENCE_DELAY,
|
||||
max_value=65535,
|
||||
|
@ -75,7 +75,7 @@ class DeconzSensorDescriptionMixin:
|
||||
"""Required values when describing secondary sensor attributes."""
|
||||
|
||||
update_key: str
|
||||
value_fn: Callable[[PydeconzSensor], float | int | None]
|
||||
value_fn: Callable[[PydeconzSensor], float | int | str | None]
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -334,14 +334,14 @@ class DeconzSensor(DeconzDevice, SensorEntity):
|
||||
"""Return the state of the sensor."""
|
||||
if self.entity_description.device_class is SensorDeviceClass.TIMESTAMP:
|
||||
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)
|
||||
|
||||
@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."""
|
||||
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:
|
||||
return attr
|
||||
|
Loading…
x
Reference in New Issue
Block a user