diff --git a/homeassistant/components/binary_sensor/deconz.py b/homeassistant/components/binary_sensor/deconz.py index 1effcf1800a..ef3ec506e3a 100644 --- a/homeassistant/components/binary_sensor/deconz.py +++ b/homeassistant/components/binary_sensor/deconz.py @@ -23,8 +23,7 @@ async def async_setup_platform(hass, config, async_add_devices, sensors = hass.data[DATA_DECONZ].sensors entities = [] - for key in sorted(sensors.keys(), key=int): - sensor = sensors[key] + for sensor in sensors.values(): if sensor and sensor.type in DECONZ_BINARY_SENSOR: entities.append(DeconzBinarySensor(sensor)) async_add_devices(entities, True) @@ -93,9 +92,9 @@ class DeconzBinarySensor(BinarySensorDevice): def device_state_attributes(self): """Return the state attributes of the sensor.""" from pydeconz.sensor import PRESENCE - attr = { - ATTR_BATTERY_LEVEL: self._sensor.battery, - } - if self._sensor.type in PRESENCE: + attr = {} + if self._sensor.battery: + attr[ATTR_BATTERY_LEVEL] = self._sensor.battery + if self._sensor.type in PRESENCE and self._sensor.dark: attr['dark'] = self._sensor.dark return attr diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index de6d3e89859..26d9fb401e4 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -17,7 +17,7 @@ from homeassistant.helpers import discovery from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.util.json import load_json, save_json -REQUIREMENTS = ['pydeconz==31'] +REQUIREMENTS = ['pydeconz==32'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/sensor/deconz.py b/homeassistant/components/sensor/deconz.py index a3c2aa683dc..081b304dc55 100644 --- a/homeassistant/components/sensor/deconz.py +++ b/homeassistant/components/sensor/deconz.py @@ -6,7 +6,8 @@ https://home-assistant.io/components/sensor.deconz/ """ from homeassistant.components.deconz import ( DOMAIN as DATA_DECONZ, DATA_DECONZ_ID) -from homeassistant.const import ATTR_BATTERY_LEVEL, CONF_EVENT, CONF_ID +from homeassistant.const import ( + ATTR_BATTERY_LEVEL, ATTR_VOLTAGE, CONF_EVENT, CONF_ID) from homeassistant.core import EventOrigin, callback from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level @@ -14,6 +15,7 @@ from homeassistant.util import slugify DEPENDENCIES = ['deconz'] +ATTR_CURRENT = 'current' ATTR_EVENT_ID = 'event_id' @@ -27,8 +29,7 @@ async def async_setup_platform(hass, config, async_add_devices, sensors = hass.data[DATA_DECONZ].sensors entities = [] - for key in sorted(sensors.keys(), key=int): - sensor = sensors[key] + for sensor in sensors.values(): if sensor and sensor.type in DECONZ_SENSOR: if sensor.type in DECONZ_REMOTE: DeconzEvent(hass, sensor) @@ -106,9 +107,12 @@ class DeconzSensor(Entity): @property def device_state_attributes(self): """Return the state attributes of the sensor.""" - attr = { - ATTR_BATTERY_LEVEL: self._sensor.battery, - } + attr = {} + if self._sensor.battery: + attr[ATTR_BATTERY_LEVEL] = self._sensor.battery + if self.unit_of_measurement == 'Watts': + attr[ATTR_CURRENT] = self._sensor.current + attr[ATTR_VOLTAGE] = self._sensor.voltage return attr diff --git a/requirements_all.txt b/requirements_all.txt index b35b3d0991a..608618eb166 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -701,7 +701,7 @@ pycsspeechtts==1.0.2 pydaikin==0.4 # homeassistant.components.deconz -pydeconz==31 +pydeconz==32 # homeassistant.components.zwave pydispatcher==2.0.5