From 3ed69cec68dfcc2e9b2e6fdd1f968e629212be16 Mon Sep 17 00:00:00 2001 From: William Scanlon Date: Mon, 14 Dec 2015 10:13:51 -0500 Subject: [PATCH] Add Egg Minder support --- .../components/sensor/wink-eggminder.py | 64 +++++++++++++++++++ homeassistant/components/wink.py | 8 +-- 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 homeassistant/components/sensor/wink-eggminder.py diff --git a/homeassistant/components/sensor/wink-eggminder.py b/homeassistant/components/sensor/wink-eggminder.py new file mode 100755 index 00000000000..9398d11d177 --- /dev/null +++ b/homeassistant/components/sensor/wink-eggminder.py @@ -0,0 +1,64 @@ +""" +homeassistant.components.egg_minder.wink +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Wink Egg Minder. +For more details about this platform, please refer to the documentation at +at https://home-assistant.io/components/sensor.wink/ +""" +import logging + +from homeassistant.helpers.entity import Entity +from homeassistant.const import CONF_ACCESS_TOKEN + +REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/' + '42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip' + '#python-wink==0.2'] + +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the Wink platform. """ + import pywink + + if discovery_info is None: + token = config.get('access_token') + + if token is None: + logging.getLogger(__name__).error( + "Missing wink access_token. " + "Get one at https://winkbearertoken.appspot.com/") + return + + pywink.set_bearer_token(token) + + add_devices(WinkEggMinder(eggtray) for eggtray in pywink.get_eggtrays()) + + +class WinkEggMinder(Entity): + """ Represents a Wink sensor. """ + + def __init__(self, wink): + self.wink = wink + + @property + def state(self): + """ Returns the state. """ + return self.egg_count + + @property + def unique_id(self): + """ Returns the id of this wink sensor """ + return "{}.{}".format(self.__class__, self.wink.deviceId()) + + @property + def name(self): + """ Returns the name of the sensor if any. """ + return self.wink.name() + + @property + def update(self): + """ Update state of the Egg Minder. """ + self.wink.updateState() + + @property + def egg_count(self): + """ The number of eggs """ + return self.wink.state() diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index 1ab82236596..2ea93cce3a7 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -17,14 +17,14 @@ from homeassistant.const import ( ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME) DOMAIN = "wink" +DEPENDENCIES = [] REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/' - '42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip' - '#python-wink==0.2'] + '9eb39eaba0717922815e673ad1114c685839d890.zip' + '#python-wink==0.1.1'] DISCOVER_LIGHTS = "wink.lights" DISCOVER_SWITCHES = "wink.switches" DISCOVER_SENSORS = "wink.sensors" -DISCOVER_LOCKS = "wink.locks" def setup(hass, config): @@ -42,7 +42,7 @@ def setup(hass, config): ('light', pywink.get_bulbs, DISCOVER_LIGHTS), ('switch', pywink.get_switches, DISCOVER_SWITCHES), ('sensor', pywink.get_sensors, DISCOVER_SENSORS), - ('lock', pywink.get_locks, DISCOVER_LOCKS)): + ('sensor', pywink.get_eggtrays, DISCOVER_SENSORS)): if func_exists(): component = get_component(component_name)