2015-08-11 12:53:55 +00:00
|
|
|
"""
|
|
|
|
Support for Wink lights.
|
2015-10-21 08:45:08 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 12:12:18 +00:00
|
|
|
https://home-assistant.io/components/light.wink/
|
2015-08-11 12:53:55 +00:00
|
|
|
"""
|
2014-12-16 08:01:15 +00:00
|
|
|
import logging
|
|
|
|
|
2016-02-08 16:53:22 +00:00
|
|
|
from homeassistant.components.light import ATTR_BRIGHTNESS, Light
|
2015-01-16 05:25:24 +00:00
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2016-03-15 11:29:49 +00:00
|
|
|
REQUIREMENTS = ['python-wink==0.6.4']
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2015-12-17 03:45:58 +00:00
|
|
|
|
2015-01-19 08:02:25 +00:00
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Setup Wink lights."""
|
2015-07-20 07:41:57 +00:00
|
|
|
import pywink
|
|
|
|
|
2015-01-11 07:47:23 +00:00
|
|
|
token = config.get(CONF_ACCESS_TOKEN)
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2015-01-19 08:02:25 +00:00
|
|
|
if not pywink.is_token_set() and token is None:
|
2015-01-11 06:53:41 +00:00
|
|
|
logging.getLogger(__name__).error(
|
|
|
|
"Missing wink access_token - "
|
|
|
|
"get one at https://winkbearertoken.appspot.com/")
|
2015-01-19 08:02:25 +00:00
|
|
|
return
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2015-01-19 08:02:25 +00:00
|
|
|
elif token is not None:
|
|
|
|
pywink.set_bearer_token(token)
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2015-01-19 08:02:25 +00:00
|
|
|
add_devices_callback(
|
|
|
|
WinkLight(light) for light in pywink.get_bulbs())
|
2014-12-16 08:01:15 +00:00
|
|
|
|
|
|
|
|
2016-02-08 16:53:22 +00:00
|
|
|
class WinkLight(Light):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Representation of a Wink light."""
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2016-02-08 16:53:22 +00:00
|
|
|
def __init__(self, wink):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Initialize the light."""
|
2016-02-08 16:53:22 +00:00
|
|
|
self.wink = wink
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return the ID of this Wink light."""
|
2016-02-08 16:53:22 +00:00
|
|
|
return "{}.{}".format(self.__class__, self.wink.device_id())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return the name of the light if any."""
|
2016-02-08 16:53:22 +00:00
|
|
|
return self.wink.name()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return true if light is on."""
|
2016-02-08 16:53:22 +00:00
|
|
|
return self.wink.state()
|
|
|
|
|
2016-02-07 06:28:29 +00:00
|
|
|
@property
|
|
|
|
def brightness(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return the brightness of the light."""
|
2016-02-07 06:28:29 +00:00
|
|
|
return int(self.wink.brightness() * 255)
|
|
|
|
|
2016-03-15 11:29:49 +00:00
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""True if connection == True."""
|
|
|
|
return self.wink.available
|
|
|
|
|
2015-01-16 05:25:24 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
def turn_on(self, **kwargs):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Turn the switch on."""
|
2015-01-16 05:25:24 +00:00
|
|
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
2014-12-16 08:01:15 +00:00
|
|
|
|
2015-01-16 05:25:24 +00:00
|
|
|
if brightness is not None:
|
2015-12-16 03:43:12 +00:00
|
|
|
self.wink.set_state(True, brightness=brightness / 255)
|
2015-01-16 05:25:24 +00:00
|
|
|
else:
|
2015-12-16 18:32:38 +00:00
|
|
|
self.wink.set_state(True)
|
2016-02-08 16:53:22 +00:00
|
|
|
|
|
|
|
def turn_off(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Turn the switch off."""
|
2016-02-08 16:53:22 +00:00
|
|
|
self.wink.set_state(False)
|
|
|
|
|
|
|
|
def update(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Update state of the light."""
|
2016-02-08 16:53:22 +00:00
|
|
|
self.wink.update_state()
|