2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tellstick switches using Tellstick Net."""
|
2018-12-10 17:44:45 +00:00
|
|
|
from homeassistant.components import switch, tellduslive
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2015-12-27 11:32:08 +00:00
|
|
|
from homeassistant.helpers.entity import ToggleEntity
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from .entry import TelldusLiveEntity
|
|
|
|
|
2015-12-27 11:32:08 +00:00
|
|
|
|
2018-12-10 17:44:45 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up tellduslive sensors dynamically."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-12-10 17:44:45 +00:00
|
|
|
async def async_discover_switch(device_id):
|
|
|
|
"""Discover and add a discovered sensor."""
|
|
|
|
client = hass.data[tellduslive.DOMAIN]
|
|
|
|
async_add_entities([TelldusLiveSwitch(client, device_id)])
|
|
|
|
|
|
|
|
async_dispatcher_connect(
|
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
tellduslive.TELLDUS_DISCOVERY_NEW.format(switch.DOMAIN, tellduslive.DOMAIN),
|
2018-12-10 17:44:45 +00:00
|
|
|
async_discover_switch,
|
|
|
|
)
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
|
2016-12-12 05:39:37 +00:00
|
|
|
class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Representation of a Tellstick switch."""
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Return true if switch is on."""
|
2018-08-26 19:25:39 +00:00
|
|
|
return self.device.is_on
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Turn the switch on."""
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.turn_on()
|
2019-03-06 12:52:25 +00:00
|
|
|
self._update_callback()
|
2015-12-27 11:32:08 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Turn the switch off."""
|
2018-08-26 19:25:39 +00:00
|
|
|
self.device.turn_off()
|
2019-03-06 12:52:25 +00:00
|
|
|
self._update_callback()
|