Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Tellstick switches using Tellstick Net."""
2 
3 from typing import Any
4 
5 from homeassistant.components import switch
6 from homeassistant.components.switch import SwitchEntity
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.dispatcher import async_dispatcher_connect
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .const import DOMAIN, TELLDUS_DISCOVERY_NEW
13 from .entity import TelldusLiveEntity
14 
15 
17  hass: HomeAssistant,
18  config_entry: ConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up tellduslive sensors dynamically."""
22 
23  async def async_discover_switch(device_id):
24  """Discover and add a discovered sensor."""
25  client = hass.data[DOMAIN]
26  async_add_entities([TelldusLiveSwitch(client, device_id)])
27 
29  hass,
30  TELLDUS_DISCOVERY_NEW.format(switch.DOMAIN, DOMAIN),
31  async_discover_switch,
32  )
33 
34 
36  """Representation of a Tellstick switch."""
37 
38  _attr_name = None
39 
40  @property
41  def is_on(self):
42  """Return true if switch is on."""
43  return self.devicedevice.is_on
44 
45  def turn_on(self, **kwargs: Any) -> None:
46  """Turn the switch on."""
47  self.devicedevice.turn_on()
48  self.schedule_update_ha_stateschedule_update_ha_state()
49 
50  def turn_off(self, **kwargs: Any) -> None:
51  """Turn the switch off."""
52  self.devicedevice.turn_off()
53  self.schedule_update_ha_stateschedule_update_ha_state()
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:20
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103