Added battery level to wink devices (#1979)
This commit is contained in:
parent
72cf7fd9c2
commit
1cd59cf2a9
8 changed files with 98 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue