Initial version wink component by @loghound

This commit is contained in:
Paulus Schoutsen 2015-01-10 22:53:41 -08:00
parent cd896627ea
commit 249cf244ca
4 changed files with 25 additions and 56 deletions

View file

@ -87,7 +87,6 @@ ATTR_FLASH = "flash"
FLASH_SHORT = "short" FLASH_SHORT = "short"
FLASH_LONG = "long" FLASH_LONG = "long"
LIGHT_PROFILES_FILE = "light_profiles.csv" LIGHT_PROFILES_FILE = "light_profiles.csv"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -1,72 +1,51 @@
""" Support for Hue lights. """ """ Support for Hue lights. """
import logging import logging
from datetime import timedelta import homeassistant.external.wink.pywink as pywink
import homeassistant.util as util
from homeassistant.helpers import ToggleDevice from homeassistant.helpers import ToggleDevice
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_PLATFORM from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_HUE, ATTR_SATURATION, ATTR_KELVIN)
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def get_devices(hass, config): def get_devices(hass, config):
""" Find and return WeMo switches. """ """ Find and return Wink lights. """
token = config.get('access_token')
try: if token is None:
# Pylint does not play nice if not every folders has an __init__.py logging.getLogger(__name__).error(
# pylint: disable=no-name-in-module, import-error "Missing wink access_token - "
import homeassistant.components.hubs.pywink.pywink as pywink "get one at https://winkbearertoken.appspot.com/")
except ImportError: return False
logging.getLogger(__name__).exception((
"Failed to import pywink. "
"Did you maybe not run `git submodule init` "
"and `git submodule update`?"))
return []
token = config["access_token"]
pywink.set_bearer_token(token) pywink.set_bearer_token(token)
switches = pywink.get_bulbs() return [WinkLight(light) for light in pywink.get_bulbs()]
# Filter out the switches and wrap in WemoSwitch object
return [WinkLight(switch) for switch in switches]
class WinkLight(ToggleDevice): class WinkLight(ToggleDevice):
""" """ Represents a Wink light """
Represents a Lifx light
http://lifx.com
"""
def __init__(self, wink): def __init__(self, wink):
self.wink = wink self.wink = wink
self.state_attr = {ATTR_FRIENDLY_NAME: wink.name()} self.state_attr = {ATTR_FRIENDLY_NAME: wink.name()}
def get_name(self): def get_name(self):
""" Returns the name of the switch if any. """ """ Returns the name of the light if any. """
return self.wink.name() return self.wink.name()
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turns the switch on. """ """ Turns the light on. """
self.wink.setState(True) self.wink.setState(True)
def turn_off(self): def turn_off(self):
""" Turns the switch off. """ """ Turns the light off. """
self.wink.setState(False) self.wink.setState(False)
def is_on(self): def is_on(self):
""" True if switch is on. """ """ True if light is on. """
return self.wink.state() return self.wink.state()
def get_state_attributes(self): def get_state_attributes(self):
""" Returns optional state attributes. """ """ Returns optional state attributes. """
return self.state_attr return self.state_attr

View file

@ -1,35 +1,26 @@
""" Support for WeMo switchces. """ """ Support for WeMo switchces. """
import logging import logging
import homeassistant as ha import homeassistant.external.wink.pywink as pywink
from homeassistant.helpers import ToggleDevice from homeassistant.helpers import ToggleDevice
from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.const import ATTR_FRIENDLY_NAME
# pylint: disable=unused-argument # pylint: disable=unused-argument
def get_devices(hass, config): def get_devices(hass, config):
""" Find and return WeMo switches. """ """ Find and return Wink switches. """
token = config.get('access_token')
try: if token is None:
# Pylint does not play nice if not every folders has an __init__.py logging.getLogger(__name__).error(
# pylint: disable=no-name-in-module, import-error "Missing wink access_token - "
import homeassistant.components.hubs.pywink.pywink as pywink "get one at https://winkbearertoken.appspot.com/")
except ImportError: return False
logging.getLogger(__name__).exception((
"Failed to import pywink. "
"Did you maybe not run `git submodule init` "
"and `git submodule update`?"))
return []
token = config["access_token"]
pywink.set_bearer_token(token) pywink.set_bearer_token(token)
switches = pywink.get_switches() return [WinkSwitch(switch) for switch in pywink.get_switches()]
# Filter out the switches and wrap in WemoSwitch object
return [WinkSwitch(switch) for switch in switches]
class WinkSwitch(ToggleDevice): class WinkSwitch(ToggleDevice):