Simplify use of binary sensor device classes in MySensors (#82946)

This commit is contained in:
Franck Nijhof 2022-11-29 20:23:57 +01:00 committed by GitHub
parent 573320a0b4
commit c36dd17780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASSES,
BinarySensorDeviceClass, BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
) )
@ -17,9 +16,9 @@ from .const import MYSENSORS_DISCOVERY, DiscoveryInfo
from .helpers import on_unload from .helpers import on_unload
SENSORS = { SENSORS = {
"S_DOOR": "door", "S_DOOR": BinarySensorDeviceClass.DOOR,
"S_MOTION": BinarySensorDeviceClass.MOTION, "S_MOTION": BinarySensorDeviceClass.MOTION,
"S_SMOKE": "smoke", "S_SMOKE": BinarySensorDeviceClass.SMOKE,
"S_SPRINKLER": BinarySensorDeviceClass.SAFETY, "S_SPRINKLER": BinarySensorDeviceClass.SAFETY,
"S_WATER_LEAK": BinarySensorDeviceClass.SAFETY, "S_WATER_LEAK": BinarySensorDeviceClass.SAFETY,
"S_SOUND": BinarySensorDeviceClass.SOUND, "S_SOUND": BinarySensorDeviceClass.SOUND,
@ -66,10 +65,7 @@ class MySensorsBinarySensor(mysensors.device.MySensorsEntity, BinarySensorEntity
return self._values.get(self.value_type) == STATE_ON return self._values.get(self.value_type) == STATE_ON
@property @property
def device_class(self) -> str | None: def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the class of this sensor, from DEVICE_CLASSES.""" """Return the class of this sensor, from DEVICE_CLASSES."""
pres = self.gateway.const.Presentation pres = self.gateway.const.Presentation
device_class = SENSORS.get(pres(self.child_type).name) return SENSORS.get(pres(self.child_type).name)
if device_class in DEVICE_CLASSES:
return device_class
return None