Added battery level to wink devices (#1979)

This commit is contained in:
William Scanlon authored and Paulus Schoutsen committed 2016-05-06 18:19:37 -07:00
1 parent 72cf7fd9c2
commit 1cd59cf2a9
8 files changed
+98 -13

No files matched your search

+16 -2
View File
@@ -7,10 +7,10 @@ at https://home-assistant.io/components/sensor.wink/
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['python-wink==0.7.5']
REQUIREMENTS = ['python-wink==0.7.6']
# These are the available sensors mapped to binary_sensor class
SENSOR_TYPES = {
@@ -48,6 +48,7 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
"""Initialize the Wink binary sensor."""
self.wink = wink
self._unit_of_measurement = self.wink.UNIT
self._battery = self.wink.battery_level
self.capability = self.wink.capability()
@property
@@ -85,3 +86,16 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
def update(self):
"""Update state of the sensor."""
self.wink.update_state()
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self._battery:
return {
ATTR_BATTERY_LEVEL: self._battery_level,
}
@property
def _battery_level(self):
"""Return the battery level."""
return self.wink.battery_level * 100