Merge branch 'dev' into mysensors-component-switch
Conflicts: homeassistant/components/sensor/__init__.py homeassistant/components/switch/__init__.py
This commit is contained in:
commit
6ff24ed047
47 files changed
+1171
-427
No files matched your search
@@ -17,7 +17,7 @@ from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.const import (
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||
from homeassistant.components import (
|
||||
group, discovery, wink, isy994, verisure, zwave, mysensors)
|
||||
group, discovery, wink, isy994, verisure, zwave, tellduslive, mysensors)
|
||||
|
||||
DOMAIN = 'switch'
|
||||
SCAN_INTERVAL = 30
|
||||
@@ -40,6 +40,7 @@ DISCOVERY_PLATFORMS = {
|
||||
isy994.DISCOVER_SWITCHES: 'isy994',
|
||||
verisure.DISCOVER_SWITCHES: 'verisure',
|
||||
zwave.DISCOVER_SWITCHES: 'zwave',
|
||||
tellduslive.DISCOVER_SWITCHES: 'tellduslive',
|
||||
mysensors.DISCOVER_SWITCHES: 'mysensors',
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
homeassistant.components.switch.tellduslive
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Tellstick switches using Tellstick Net and
|
||||
the Telldus Live online service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.tellduslive/
|
||||
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (STATE_ON, STATE_OFF, STATE_UNKNOWN)
|
||||
from homeassistant.components import tellduslive
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DEPENDENCIES = ['tellduslive']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Find and return Tellstick switches. """
|
||||
switches = tellduslive.NETWORK.get_switches()
|
||||
add_devices([TelldusLiveSwitch(switch["name"],
|
||||
switch["id"])
|
||||
for switch in switches if switch["type"] == "device"])
|
||||
|
||||
|
||||
class TelldusLiveSwitch(ToggleEntity):
|
||||
""" Represents a Tellstick switch. """
|
||||
|
||||
def __init__(self, name, switch_id):
|
||||
self._name = name
|
||||
self._id = switch_id
|
||||
self._state = STATE_UNKNOWN
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" Tells Home Assistant to poll this entity. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the switch if any. """
|
||||
return self._name
|
||||
|
||||
def update(self):
|
||||
from tellive.live import const
|
||||
state = tellduslive.NETWORK.get_switch_state(self._id)
|
||||
if state == const.TELLSTICK_TURNON:
|
||||
self._state = STATE_ON
|
||||
elif state == const.TELLSTICK_TURNOFF:
|
||||
self._state = STATE_OFF
|
||||
else:
|
||||
self._state = STATE_UNKNOWN
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if switch is on. """
|
||||
return self._state == STATE_ON
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turns the switch on. """
|
||||
if tellduslive.NETWORK.turn_switch_on(self._id):
|
||||
self._state = STATE_ON
|
||||
self.update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" Turns the switch off. """
|
||||
if tellduslive.NETWORK.turn_switch_off(self._id):
|
||||
self._state = STATE_OFF
|
||||
self.update_ha_state()
|
||||
@@ -25,7 +25,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
||||
switches.extend([
|
||||
VerisureSmartplug(value)
|
||||
for value in verisure.get_smartplug_status().values()
|
||||
for value in verisure.SMARTPLUG_STATUS.values()
|
||||
if verisure.SHOW_SMARTPLUGS
|
||||
])
|
||||
|
||||
@@ -36,31 +36,29 @@ class VerisureSmartplug(SwitchDevice):
|
||||
""" Represents a Verisure smartplug. """
|
||||
def __init__(self, smartplug_status):
|
||||
self._id = smartplug_status.id
|
||||
self.status_on = verisure.MY_PAGES.SMARTPLUG_ON
|
||||
self.status_off = verisure.MY_PAGES.SMARTPLUG_OFF
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Get the name (location) of the smartplug. """
|
||||
return verisure.get_smartplug_status()[self._id].location
|
||||
return verisure.SMARTPLUG_STATUS[self._id].location
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" Returns True if on """
|
||||
plug_status = verisure.get_smartplug_status()[self._id].status
|
||||
return plug_status == self.status_on
|
||||
plug_status = verisure.SMARTPLUG_STATUS[self._id].status
|
||||
return plug_status == 'on'
|
||||
|
||||
def turn_on(self):
|
||||
""" Set smartplug status on. """
|
||||
verisure.MY_PAGES.set_smartplug_status(
|
||||
self._id,
|
||||
self.status_on)
|
||||
verisure.MY_PAGES.smartplug.set(self._id, 'on')
|
||||
verisure.MY_PAGES.smartplug.wait_while_updating(self._id, 'on')
|
||||
verisure.update_smartplug()
|
||||
|
||||
def turn_off(self):
|
||||
""" Set smartplug status off. """
|
||||
verisure.MY_PAGES.set_smartplug_status(
|
||||
self._id,
|
||||
self.status_off)
|
||||
verisure.MY_PAGES.smartplug.set(self._id, 'off')
|
||||
verisure.MY_PAGES.smartplug.wait_while_updating(self._id, 'off')
|
||||
verisure.update_smartplug()
|
||||
|
||||
def update(self):
|
||||
verisure.update()
|
||||
verisure.update_smartplug()
|
||||
@@ -9,11 +9,14 @@ https://home-assistant.io/components/switch.wemo/
|
||||
import logging
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, STATE_STANDBY
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, STATE_STANDBY, EVENT_HOMEASSISTANT_STOP)
|
||||
|
||||
REQUIREMENTS = ['pywemo==0.3.3']
|
||||
REQUIREMENTS = ['pywemo==0.3.4']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_WEMO_SUBSCRIPTION_REGISTRY = None
|
||||
|
||||
|
||||
# pylint: disable=unused-argument, too-many-function-args
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
@@ -21,6 +24,18 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
import pywemo
|
||||
import pywemo.discovery as discovery
|
||||
|
||||
global _WEMO_SUBSCRIPTION_REGISTRY
|
||||
if _WEMO_SUBSCRIPTION_REGISTRY is None:
|
||||
_WEMO_SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry()
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.start()
|
||||
|
||||
def stop_wemo(event):
|
||||
""" Shutdown Wemo subscriptions and subscription thread on exit"""
|
||||
_LOGGER.info("Shutting down subscriptions.")
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.stop()
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo)
|
||||
|
||||
if discovery_info is not None:
|
||||
location = discovery_info[2]
|
||||
mac = discovery_info[3]
|
||||
@@ -47,6 +62,23 @@ class WemoSwitch(SwitchDevice):
|
||||
self.insight_params = None
|
||||
self.maker_params = None
|
||||
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.register(wemo)
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.on(
|
||||
wemo, None, self._update_callback)
|
||||
|
||||
def _update_callback(self, _device, _params):
|
||||
""" Called by the wemo device callback to update state. """
|
||||
_LOGGER.info(
|
||||
'Subscription update for %s, sevice=%s',
|
||||
self.name, _device)
|
||||
self.update_ha_state(True)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling should be needed with subscriptions """
|
||||
# but leave in for initial version in case of issues.
|
||||
return True
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this WeMo switch """
|
||||
|
||||
Reference in new issue
Block a user