Added wink component to auto-load other needed components

This commit is contained in:
Paulus Schoutsen committed 2015-01-10 23:47:23 -08:00
1 parent 249cf244ca
commit 6cd53f2ddf
10 files changed
+147 -56

No files matched your search

+16 -13
View File
@@ -12,7 +12,7 @@ from homeassistant.const import (
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
from homeassistant.helpers import (
extract_entity_ids, platform_devices_from_config)
from homeassistant.components import group, discovery
from homeassistant.components import group, discovery, wink
DOMAIN = 'switch'
DEPENDENCIES = []
@@ -29,8 +29,9 @@ ATTR_CURRENT_POWER_MWH = "current_power_mwh"
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
# Maps discovered services to their platforms
DISCOVERY = {
discovery.services.BELKIN_WEMO: 'wemo'
DISCOVERY_PLATFORMS = {
discovery.services.BELKIN_WEMO: 'wemo',
wink.DISCOVER_SWITCHES: 'wink',
}
_LOGGER = logging.getLogger(__name__)
@@ -82,22 +83,24 @@ def setup(hass, config):
def switch_discovered(service, info):
""" Called when a switch is discovered. """
platform = get_component("{}.{}".format(DOMAIN, DISCOVERY[service]))
platform = get_component("{}.{}".format(
DOMAIN, DISCOVERY_PLATFORMS[service]))
switch = platform.device_discovered(hass, config, info)
discovered = platform.device_discovered(hass, config, info)
if switch is not None and switch not in switches.values():
switch.entity_id = util.ensure_unique_string(
ENTITY_ID_FORMAT.format(util.slugify(switch.get_name())),
switches.keys())
for switch in discovered:
if switch is not None and switch not in switches.values():
switch.entity_id = util.ensure_unique_string(
ENTITY_ID_FORMAT.format(util.slugify(switch.get_name())),
switches.keys())
switches[switch.entity_id] = switch
switches[switch.entity_id] = switch
switch.update_ha_state(hass)
switch.update_ha_state(hass)
switch_group.update_tracked_entity_ids(switches.keys())
switch_group.update_tracked_entity_ids(switches.keys())
discovery.listen(hass, discovery.services.BELKIN_WEMO, switch_discovered)
discovery.listen(hass, DISCOVERY_PLATFORMS.keys(), switch_discovered)
def handle_switch_service(service):
""" Handles calls to the switch services. """
+3 -3
View File
@@ -24,16 +24,16 @@ def get_devices(hass, config):
if isinstance(switch, pywemo.Switch)]
def device_discovered(hass, config, info):
def devices_discovered(hass, config, info):
""" Called when a device is discovered. """
_, discovery = get_pywemo()
if discovery is None:
return
return []
device = discovery.device_from_description(info)
return None if device is None else WemoSwitch(device)
return [] if device is None else [WemoSwitch(device)]
def get_pywemo():
+15 -3
View File
@@ -1,25 +1,37 @@
""" Support for WeMo switchces. """
import logging
# pylint: disable=no-name-in-module, import-error
import homeassistant.external.wink.pywink as pywink
from homeassistant.helpers import ToggleDevice
from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_ACCESS_TOKEN
# pylint: disable=unused-argument
def get_devices(hass, config):
""" Find and return Wink switches. """
token = config.get('access_token')
token = config.get(CONF_ACCESS_TOKEN)
if token is None:
logging.getLogger(__name__).error(
"Missing wink access_token - "
"get one at https://winkbearertoken.appspot.com/")
return False
return []
pywink.set_bearer_token(token)
return get_switches()
# pylint: disable=unused-argument
def devices_discovered(hass, config, info):
""" Called when a device is discovered. """
return get_switches()
def get_switches():
""" Returns the Wink switches. """
return [WinkSwitch(switch) for switch in pywink.get_switches()]