1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/tellduslive/switch.py
Franck Nijhof 4c83ecd7bd
Fix incorrect usage of ToggleEntity in switch platforms (#64620)
Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
2022-01-21 13:17:45 +01:00

48 lines
1.5 KiB
Python

"""Support for Tellstick switches using Tellstick Net."""
from homeassistant.components import switch, tellduslive
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .entry import TelldusLiveEntity
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up tellduslive sensors dynamically."""
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,
tellduslive.TELLDUS_DISCOVERY_NEW.format(switch.DOMAIN, tellduslive.DOMAIN),
async_discover_switch,
)
class TelldusLiveSwitch(TelldusLiveEntity, SwitchEntity):
"""Representation of a Tellstick switch."""
@property
def is_on(self):
"""Return true if switch is on."""
return self.device.is_on
def turn_on(self, **kwargs):
"""Turn the switch on."""
self.device.turn_on()
self._update_callback()
def turn_off(self, **kwargs):
"""Turn the switch off."""
self.device.turn_off()
self._update_callback()