core/homeassistant/components/tellduslive/switch.py

41 lines
1.2 KiB
Python
Raw Normal View History

"""Support for Tellstick switches using Tellstick Net."""
from homeassistant.components import switch, tellduslive
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import ToggleEntity
from .entry import TelldusLiveEntity
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
2019-07-31 19:25:30 +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),
async_discover_switch,
)
class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity):
2016-03-08 12:35:39 +00:00
"""Representation of a Tellstick switch."""
@property
def is_on(self):
2016-03-08 12:35:39 +00:00
"""Return true if switch is on."""
return self.device.is_on
def turn_on(self, **kwargs):
2016-03-08 12:35:39 +00:00
"""Turn the switch on."""
self.device.turn_on()
self._update_callback()
def turn_off(self, **kwargs):
2016-03-08 12:35:39 +00:00
"""Turn the switch off."""
self.device.turn_off()
self._update_callback()