Telldus Live: (#4645)

- Implemented support for covers and dimmable lights.
- Removed global object, use hass.data.
- Disabled polling via update.
- Inherit from common TelldusLiveEntity device.
- Configurable polling interval
- Use https API endpoint
- Use tellduslive package
This commit is contained in:
Erik Eriksson authored and Paulus Schoutsen committed 2016-12-11 21:39:37 -08:00
1 parent 04aa4e898a
commit 2a7fa5afc3
6 files changed
+314 -275

No files matched your search

+8 -38
View File
@@ -9,7 +9,7 @@ https://home-assistant.io/components/switch.tellduslive/
"""
import logging
from homeassistant.components import tellduslive
from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.helpers.entity import ToggleEntity
_LOGGER = logging.getLogger(__name__)
@@ -19,53 +19,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Tellstick switches."""
if discovery_info is None:
return
add_devices(TelldusLiveSwitch(switch) for switch in discovery_info)
add_devices(TelldusLiveSwitch(hass, switch) for switch in discovery_info)
class TelldusLiveSwitch(ToggleEntity):
class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity):
"""Representation of a Tellstick switch."""
def __init__(self, switch_id):
"""Initialize the switch."""
self._id = switch_id
self.update()
_LOGGER.debug("created switch %s", self)
def update(self):
"""Get the latest date and update the state."""
tellduslive.NETWORK.update_switches()
self._switch = tellduslive.NETWORK.get_switch(self._id)
@property
def should_poll(self):
"""Polling is needed."""
return True
@property
def assumed_state(self):
"""Return true if unable to access real state of entity."""
return True
@property
def name(self):
"""Return the name of the switch if any."""
return self._switch["name"]
@property
def available(self):
"""Return the state of the switch."""
return not self._switch.get("offline", False)
@property
def is_on(self):
"""Return true if switch is on."""
from tellive.live import const
return self._switch["state"] == const.TELLSTICK_TURNON
return self.device.is_on()
def turn_on(self, **kwargs):
"""Turn the switch on."""
tellduslive.NETWORK.turn_switch_on(self._id)
self.device.turn_on()
self.changed()
def turn_off(self, **kwargs):
"""Turn the switch off."""
tellduslive.NETWORK.turn_switch_off(self._id)
self.device.turn_off()
self.changed()