Moved Wink binary sensors to a binary sensor class

This commit is contained in:
William Scanlon 2016-02-23 14:20:54 -05:00
parent dc02370b43
commit 5a64ef2c98
9 changed files with 131 additions and 23 deletions

View file

@ -6,10 +6,13 @@ at https://home-assistant.io/components/sensor.wink/
"""
import logging
from homeassistant.const import CONF_ACCESS_TOKEN, STATE_CLOSED, STATE_OPEN
from homeassistant.const import (CONF_ACCESS_TOKEN, STATE_CLOSED,
STATE_OPEN, TEMP_CELCIUS)
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['python-wink==0.6.1']
REQUIREMENTS = ['python-wink==0.6.2']
SENSOR_TYPES = ['temperature', 'humidity']
def setup_platform(hass, config, add_devices, discovery_info=None):
@ -27,7 +30,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
pywink.set_bearer_token(token)
add_devices(WinkSensorDevice(sensor) for sensor in pywink.get_sensors())
for sensor in pywink.get_sensors():
if sensor.capability() in SENSOR_TYPES:
add_devices([WinkSensorDevice(sensor)])
add_devices(WinkEggMinder(eggtray) for eggtray in pywink.get_eggtrays())
@ -36,11 +42,26 @@ class WinkSensorDevice(Entity):
def __init__(self, wink):
self.wink = wink
self.capability = self.wink.capability()
if self.wink.UNIT == "°":
self._unit_of_measurement = TEMP_CELCIUS
else:
self._unit_of_measurement = self.wink.UNIT
@property
def state(self):
"""Returns the state."""
return STATE_OPEN if self.is_open else STATE_CLOSED
if self.capability == "humidity":
return self.wink.humidity_percentage()
elif self.capability == "temperature":
return self.wink.temperature_float()
else:
return STATE_OPEN if self.is_open else STATE_CLOSED
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity, if any. """
return self._unit_of_measurement
@property
def unique_id(self):