core/homeassistant/components/wink.py

103 lines
3.0 KiB
Python
Raw Normal View History

"""
2016-03-07 17:49:31 +00:00
Support for Wink hubs.
2015-10-23 20:32:36 +00:00
For more details about this component, please refer to the documentation at
2015-11-09 12:12:18 +00:00
https://home-assistant.io/components/wink/
"""
import logging
from homeassistant import bootstrap
2016-02-19 05:27:50 +00:00
from homeassistant.const import (
ATTR_DISCOVERED, ATTR_SERVICE, CONF_ACCESS_TOKEN,
EVENT_PLATFORM_DISCOVERED)
from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import ToggleEntity
2016-02-19 05:27:50 +00:00
from homeassistant.loader import get_component
DOMAIN = "wink"
REQUIREMENTS = ['python-wink==0.7.5']
DISCOVER_LIGHTS = "wink.lights"
DISCOVER_SWITCHES = "wink.switches"
DISCOVER_SENSORS = "wink.sensors"
DISCOVER_BINARY_SENSORS = "wink.binary_sensors"
2015-12-14 23:31:09 +00:00
DISCOVER_LOCKS = "wink.locks"
2016-02-01 02:39:04 +00:00
DISCOVER_GARAGE_DOORS = "wink.garage_doors"
2015-01-20 04:23:31 +00:00
def setup(hass, config):
2016-03-07 17:49:31 +00:00
"""Setup the Wink component."""
logger = logging.getLogger(__name__)
if not validate_config(config, {DOMAIN: [CONF_ACCESS_TOKEN]}, logger):
return False
import pywink
pywink.set_bearer_token(config[DOMAIN][CONF_ACCESS_TOKEN])
# Load components for the devices in the Wink that we support
for component_name, func_exists, discovery_type in (
('light', pywink.get_bulbs, DISCOVER_LIGHTS),
2016-01-06 17:22:50 +00:00
('switch', lambda: pywink.get_switches or
2016-01-21 16:12:00 +00:00
pywink.get_sirens or
2016-01-06 17:22:50 +00:00
pywink.get_powerstrip_outlets, DISCOVER_SWITCHES),
('binary_sensor', pywink.get_sensors, DISCOVER_BINARY_SENSORS),
2016-01-06 17:22:50 +00:00
('sensor', lambda: pywink.get_sensors or
pywink.get_eggtrays, DISCOVER_SENSORS),
2016-02-01 02:39:04 +00:00
('lock', pywink.get_locks, DISCOVER_LOCKS),
('garage_door', pywink.get_garage_doors, DISCOVER_GARAGE_DOORS)):
if func_exists():
2015-01-11 22:21:44 +00:00
component = get_component(component_name)
# Ensure component is loaded
bootstrap.setup_component(hass, component.DOMAIN, config)
# Fire discovery event
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
ATTR_SERVICE: discovery_type,
ATTR_DISCOVERED: {}
})
2015-01-11 22:21:44 +00:00
return True
2015-01-16 05:25:24 +00:00
2015-01-20 04:23:31 +00:00
class WinkToggleDevice(ToggleEntity):
2016-03-07 17:49:31 +00:00
"""Represents a Wink toggle (switch) device."""
2016-03-08 16:55:57 +00:00
2015-01-16 05:25:24 +00:00
def __init__(self, wink):
2016-03-08 16:55:57 +00:00
"""Initialize the Wink device."""
2015-01-16 05:25:24 +00:00
self.wink = wink
@property
def unique_id(self):
2016-03-07 17:49:31 +00:00
"""Return the ID of this Wink device."""
return "{}.{}".format(self.__class__, self.wink.device_id())
2015-01-16 05:25:24 +00:00
@property
def name(self):
2016-03-07 17:49:31 +00:00
"""Return the name of the device."""
2015-01-16 05:25:24 +00:00
return self.wink.name()
@property
def is_on(self):
2016-03-08 16:55:57 +00:00
"""Return true if device is on."""
2015-01-16 05:25:24 +00:00
return self.wink.state()
@property
def available(self):
"""True if connection == True."""
return self.wink.available
2015-01-16 05:25:24 +00:00
def turn_on(self, **kwargs):
2016-03-08 16:55:57 +00:00
"""Turn the device on."""
self.wink.set_state(True)
2015-01-16 05:25:24 +00:00
def turn_off(self):
2016-03-08 16:55:57 +00:00
"""Turn the device off."""
self.wink.set_state(False)
2015-01-16 05:25:24 +00:00
def update(self):
2016-03-07 17:49:31 +00:00
"""Update state of the device."""
self.wink.update_state()