From c6c4c07f2d351d2de38d168cc590b33e68fe3ba0 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 28 Jul 2019 21:01:52 +0200 Subject: [PATCH] deCONZ - cleanup sensor attributes (#25540) * Improve attributes --- homeassistant/components/deconz/sensor.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index df3059fdf0e..a46a4bbf55c 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -1,5 +1,5 @@ """Support for deCONZ sensors.""" -from pydeconz.sensor import LightLevel, Switch +from pydeconz.sensor import Consumption, Daylight, LightLevel, Power, Switch from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_TEMPERATURE, ATTR_VOLTAGE, DEVICE_CLASS_BATTERY) @@ -97,20 +97,20 @@ class DeconzSensor(DeconzDevice): if self._device.secondary_temperature is not None: attr[ATTR_TEMPERATURE] = self._device.secondary_temperature - if self._device.type in LightLevel.ZHATYPE and \ + if self._device.type in Consumption.ZHATYPE: + attr[ATTR_POWER] = self._device.power + + elif self._device.type in Daylight.ZHATYPE: + attr[ATTR_DAYLIGHT] = self._device.daylight + + elif self._device.type in LightLevel.ZHATYPE and \ self._device.dark is not None: attr[ATTR_DARK] = self._device.dark - if self.unit_of_measurement == 'W': + elif self._device.type in Power.ZHATYPE: attr[ATTR_CURRENT] = self._device.current attr[ATTR_VOLTAGE] = self._device.voltage - if self.unit_of_measurement == 'kWh': - attr[ATTR_POWER] = self._device.power - - if self._device.SENSOR_CLASS == 'daylight': - attr[ATTR_DAYLIGHT] = self._device.daylight - return attr