diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index 0e8a73bbc36..a8cc5bc5808 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -11,7 +11,7 @@ from pydeconz.sensor import ( GenericFlag, OpenClose, Presence, - SensorBase as PydeconzSensor, + SensorResources, Vibration, Water, ) @@ -55,7 +55,7 @@ class DeconzBinarySensorDescriptionMixin: suffix: str update_key: str - value_fn: Callable[[PydeconzSensor], bool | None] + value_fn: Callable[[SensorResources], bool | None] @dataclass @@ -70,7 +70,7 @@ ENTITY_DESCRIPTIONS = { Alarm: [ DeconzBinarySensorDescription( 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="", update_key="alarm", device_class=BinarySensorDeviceClass.SAFETY, @@ -79,7 +79,9 @@ ENTITY_DESCRIPTIONS = { CarbonMonoxide: [ DeconzBinarySensorDescription( 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="", update_key="carbonmonoxide", device_class=BinarySensorDeviceClass.CO, @@ -88,14 +90,16 @@ ENTITY_DESCRIPTIONS = { Fire: [ DeconzBinarySensorDescription( 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="", update_key="fire", device_class=BinarySensorDeviceClass.SMOKE, ), DeconzBinarySensorDescription( 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", update_key="test", device_class=BinarySensorDeviceClass.SMOKE, @@ -105,7 +109,9 @@ ENTITY_DESCRIPTIONS = { GenericFlag: [ DeconzBinarySensorDescription( 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="", update_key="flag", ) @@ -113,7 +119,9 @@ ENTITY_DESCRIPTIONS = { OpenClose: [ DeconzBinarySensorDescription( 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="", update_key="open", device_class=BinarySensorDeviceClass.OPENING, @@ -122,7 +130,9 @@ ENTITY_DESCRIPTIONS = { Presence: [ DeconzBinarySensorDescription( 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="", update_key="presence", device_class=BinarySensorDeviceClass.MOTION, @@ -131,7 +141,9 @@ ENTITY_DESCRIPTIONS = { Vibration: [ DeconzBinarySensorDescription( 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="", update_key="vibration", device_class=BinarySensorDeviceClass.VIBRATION, @@ -140,7 +152,7 @@ ENTITY_DESCRIPTIONS = { Water: [ DeconzBinarySensorDescription( 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="", update_key="water", device_class=BinarySensorDeviceClass.MOISTURE, @@ -178,7 +190,7 @@ async def async_setup_entry( gateway.entities[DOMAIN] = set() @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.""" entities: list[DeconzBinarySensor] = [] @@ -225,12 +237,12 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity): """Representation of a deCONZ binary sensor.""" TYPE = DOMAIN - _device: PydeconzSensor + _device: SensorResources entity_description: DeconzBinarySensorDescription def __init__( self, - device: PydeconzSensor, + device: SensorResources, gateway: DeconzGateway, description: DeconzBinarySensorDescription, ) -> None: