Added battery level to wink devices (#1979)

This commit is contained in:
William Scanlon 2016-05-06 21:19:37 -04:00 committed by Paulus Schoutsen
parent 72cf7fd9c2
commit 1cd59cf2a9
8 changed files with 98 additions and 13 deletions

View file

@ -7,10 +7,10 @@ at https://home-assistant.io/components/sensor.wink/
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorDevice 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 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 # These are the available sensors mapped to binary_sensor class
SENSOR_TYPES = { SENSOR_TYPES = {
@ -48,6 +48,7 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
"""Initialize the Wink binary sensor.""" """Initialize the Wink binary sensor."""
self.wink = wink self.wink = wink
self._unit_of_measurement = self.wink.UNIT self._unit_of_measurement = self.wink.UNIT
self._battery = self.wink.battery_level
self.capability = self.wink.capability() self.capability = self.wink.capability()
@property @property
@ -85,3 +86,16 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
def update(self): def update(self):
"""Update state of the sensor.""" """Update state of the sensor."""
self.wink.update_state() 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

View file

@ -7,9 +7,9 @@ https://home-assistant.io/components/garage_door.wink/
import logging import logging
from homeassistant.components.garage_door import GarageDoorDevice from homeassistant.components.garage_door import GarageDoorDevice
from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
@ -37,6 +37,7 @@ class WinkGarageDoorDevice(GarageDoorDevice):
def __init__(self, wink): def __init__(self, wink):
"""Initialize the garage door.""" """Initialize the garage door."""
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level
@property @property
def unique_id(self): def unique_id(self):
@ -69,3 +70,16 @@ class WinkGarageDoorDevice(GarageDoorDevice):
def open_door(self): def open_door(self):
"""Open the door.""" """Open the door."""
self.wink.set_state(1) self.wink.set_state(1)
@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

View file

@ -13,7 +13,7 @@ from homeassistant.util import color as color_util
from homeassistant.util.color import \ from homeassistant.util.color import \
color_temperature_mired_to_kelvin as mired_to_kelvin color_temperature_mired_to_kelvin as mired_to_kelvin
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):

View file

@ -7,9 +7,9 @@ https://home-assistant.io/components/lock.wink/
import logging import logging
from homeassistant.components.lock import LockDevice from homeassistant.components.lock import LockDevice
from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.const import CONF_ACCESS_TOKEN, ATTR_BATTERY_LEVEL
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
@ -36,6 +36,7 @@ class WinkLockDevice(LockDevice):
def __init__(self, wink): def __init__(self, wink):
"""Initialize the lock.""" """Initialize the lock."""
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level
@property @property
def unique_id(self): def unique_id(self):
@ -68,3 +69,16 @@ class WinkLockDevice(LockDevice):
def unlock(self, **kwargs): def unlock(self, **kwargs):
"""Unlock the device.""" """Unlock the device."""
self.wink.set_state(False) self.wink.set_state(False)
@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

View file

@ -7,10 +7,11 @@ at https://home-assistant.io/components/sensor.wink/
import logging import logging
from homeassistant.const import (CONF_ACCESS_TOKEN, STATE_CLOSED, from homeassistant.const import (CONF_ACCESS_TOKEN, STATE_CLOSED,
STATE_OPEN, TEMP_CELSIUS) STATE_OPEN, TEMP_CELSIUS,
ATTR_BATTERY_LEVEL)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
SENSOR_TYPES = ['temperature', 'humidity'] SENSOR_TYPES = ['temperature', 'humidity']
@ -44,6 +45,7 @@ class WinkSensorDevice(Entity):
"""Initialize the sensor.""" """Initialize the sensor."""
self.wink = wink self.wink = wink
self.capability = self.wink.capability() self.capability = self.wink.capability()
self._battery = self.wink.battery_level
if self.wink.UNIT == "°": if self.wink.UNIT == "°":
self._unit_of_measurement = TEMP_CELSIUS self._unit_of_measurement = TEMP_CELSIUS
else: else:
@ -88,6 +90,19 @@ class WinkSensorDevice(Entity):
"""Return true if door is open.""" """Return true if door is open."""
return self.wink.state() return self.wink.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
class WinkEggMinder(Entity): class WinkEggMinder(Entity):
"""Representation of a Wink Egg Minder.""" """Representation of a Wink Egg Minder."""
@ -95,6 +110,7 @@ class WinkEggMinder(Entity):
def __init__(self, wink): def __init__(self, wink):
"""Initialize the sensor.""" """Initialize the sensor."""
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level
@property @property
def state(self): def state(self):
@ -114,3 +130,16 @@ class WinkEggMinder(Entity):
def update(self): def update(self):
"""Update state of the Egg Minder.""" """Update state of the Egg Minder."""
self.wink.update_state() 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

View file

@ -9,7 +9,7 @@ import logging
from homeassistant.components.wink import WinkToggleDevice from homeassistant.components.wink import WinkToggleDevice
from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):

View file

@ -9,13 +9,13 @@ import logging
from homeassistant import bootstrap from homeassistant import bootstrap
from homeassistant.const import ( from homeassistant.const import (
ATTR_DISCOVERED, ATTR_SERVICE, CONF_ACCESS_TOKEN, ATTR_DISCOVERED, ATTR_SERVICE, CONF_ACCESS_TOKEN,
EVENT_PLATFORM_DISCOVERED) EVENT_PLATFORM_DISCOVERED, ATTR_BATTERY_LEVEL)
from homeassistant.helpers import validate_config from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity import ToggleEntity
from homeassistant.loader import get_component from homeassistant.loader import get_component
DOMAIN = "wink" DOMAIN = "wink"
REQUIREMENTS = ['python-wink==0.7.5'] REQUIREMENTS = ['python-wink==0.7.6']
DISCOVER_LIGHTS = "wink.lights" DISCOVER_LIGHTS = "wink.lights"
DISCOVER_SWITCHES = "wink.switches" DISCOVER_SWITCHES = "wink.switches"
@ -68,6 +68,7 @@ class WinkToggleDevice(ToggleEntity):
def __init__(self, wink): def __init__(self, wink):
"""Initialize the Wink device.""" """Initialize the Wink device."""
self.wink = wink self.wink = wink
self._battery = self.wink.battery_level
@property @property
def unique_id(self): def unique_id(self):
@ -100,3 +101,16 @@ class WinkToggleDevice(ToggleEntity):
def update(self): def update(self):
"""Update state of the device.""" """Update state of the device."""
self.wink.update_state() 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

View file

@ -259,7 +259,7 @@ python-twitch==1.2.0
# homeassistant.components.lock.wink # homeassistant.components.lock.wink
# homeassistant.components.sensor.wink # homeassistant.components.sensor.wink
# homeassistant.components.switch.wink # homeassistant.components.switch.wink
python-wink==0.7.5 python-wink==0.7.6
# homeassistant.components.keyboard # homeassistant.components.keyboard
pyuserinput==0.1.9 pyuserinput==0.1.9