Fix state_class for deCONZ power sensors (#56586)

* Fix state_class for power sensors
Rewrite entity descriptions for binary sensor and sensor platforms

* Remove icon if device_class is specified
This commit is contained in:
Robert Svensson
2021-09-25 20:54:55 +02:00
committed by GitHub
parent d4ebcf2ba5
commit 8db0bd3c0e
3 changed files with 81 additions and 59 deletions

View File

@@ -11,6 +11,7 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_VIBRATION,
DOMAIN,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.core import callback
@@ -24,13 +25,31 @@ ATTR_ORIENTATION = "orientation"
ATTR_TILTANGLE = "tiltangle"
ATTR_VIBRATIONSTRENGTH = "vibrationstrength"
DEVICE_CLASS = {
CarbonMonoxide: DEVICE_CLASS_GAS,
Fire: DEVICE_CLASS_SMOKE,
OpenClose: DEVICE_CLASS_OPENING,
Presence: DEVICE_CLASS_MOTION,
Vibration: DEVICE_CLASS_VIBRATION,
Water: DEVICE_CLASS_MOISTURE,
ENTITY_DESCRIPTIONS = {
CarbonMonoxide: BinarySensorEntityDescription(
key="carbonmonoxide",
device_class=DEVICE_CLASS_GAS,
),
Fire: BinarySensorEntityDescription(
key="fire",
device_class=DEVICE_CLASS_SMOKE,
),
OpenClose: BinarySensorEntityDescription(
key="openclose",
device_class=DEVICE_CLASS_OPENING,
),
Presence: BinarySensorEntityDescription(
key="presence",
device_class=DEVICE_CLASS_MOTION,
),
Vibration: BinarySensorEntityDescription(
key="vibration",
device_class=DEVICE_CLASS_VIBRATION,
),
Water: BinarySensorEntityDescription(
key="water",
device_class=DEVICE_CLASS_MOISTURE,
),
}
@@ -84,7 +103,9 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
def __init__(self, device, gateway):
"""Initialize deCONZ binary sensor."""
super().__init__(device, gateway)
self._attr_device_class = DEVICE_CLASS.get(type(self._device))
if entity_description := ENTITY_DESCRIPTIONS.get(type(device)):
self.entity_description = entity_description
@callback
def async_update_callback(self, force_update=False):