2014-12-16 00:01:15 -08:00
|
|
|
""" Support for Hue lights. """
|
|
|
|
import logging
|
|
|
|
|
2015-01-10 23:47:23 -08:00
|
|
|
# pylint: disable=no-name-in-module, import-error
|
2015-01-10 22:53:41 -08:00
|
|
|
import homeassistant.external.wink.pywink as pywink
|
2014-12-16 00:01:15 -08:00
|
|
|
|
|
|
|
from homeassistant.helpers import ToggleDevice
|
2015-01-10 23:47:23 -08:00
|
|
|
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_ACCESS_TOKEN
|
2014-12-16 00:01:15 -08:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def get_devices(hass, config):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" Find and return Wink lights. """
|
2015-01-10 23:47:23 -08:00
|
|
|
token = config.get(CONF_ACCESS_TOKEN)
|
2014-12-16 00:01:15 -08:00
|
|
|
|
2015-01-10 22:53:41 -08:00
|
|
|
if token is None:
|
|
|
|
logging.getLogger(__name__).error(
|
|
|
|
"Missing wink access_token - "
|
|
|
|
"get one at https://winkbearertoken.appspot.com/")
|
2015-01-10 23:47:23 -08:00
|
|
|
return []
|
2014-12-16 00:01:15 -08:00
|
|
|
|
|
|
|
pywink.set_bearer_token(token)
|
|
|
|
|
2015-01-10 23:47:23 -08:00
|
|
|
return get_lights()
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def devices_discovered(hass, config, info):
|
|
|
|
""" Called when a device is discovered. """
|
|
|
|
return get_lights()
|
|
|
|
|
|
|
|
|
|
|
|
def get_lights():
|
|
|
|
""" Returns the Wink switches. """
|
2015-01-10 22:53:41 -08:00
|
|
|
return [WinkLight(light) for light in pywink.get_bulbs()]
|
2014-12-16 00:01:15 -08:00
|
|
|
|
|
|
|
|
|
|
|
class WinkLight(ToggleDevice):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" Represents a Wink light """
|
2014-12-16 00:01:15 -08:00
|
|
|
|
|
|
|
def __init__(self, wink):
|
|
|
|
self.wink = wink
|
|
|
|
self.state_attr = {ATTR_FRIENDLY_NAME: wink.name()}
|
|
|
|
|
|
|
|
def get_name(self):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" Returns the name of the light if any. """
|
2014-12-16 00:01:15 -08:00
|
|
|
return self.wink.name()
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" Turns the light on. """
|
2014-12-16 00:01:15 -08:00
|
|
|
self.wink.setState(True)
|
|
|
|
|
|
|
|
def turn_off(self):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" Turns the light off. """
|
2014-12-16 00:01:15 -08:00
|
|
|
self.wink.setState(False)
|
|
|
|
|
|
|
|
def is_on(self):
|
2015-01-10 22:53:41 -08:00
|
|
|
""" True if light is on. """
|
2014-12-16 00:01:15 -08:00
|
|
|
return self.wink.state()
|
|
|
|
|
|
|
|
def get_state_attributes(self):
|
|
|
|
""" Returns optional state attributes. """
|
|
|
|
return self.state_attr
|