Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Tellstick switches."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.switch import SwitchEntity
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
9 
10 from .const import (
11  ATTR_DISCOVER_CONFIG,
12  ATTR_DISCOVER_DEVICES,
13  DATA_TELLSTICK,
14  DEFAULT_SIGNAL_REPETITIONS,
15 )
16 from .entity import TellstickDevice
17 
18 
20  hass: HomeAssistant,
21  config: ConfigType,
22  add_entities: AddEntitiesCallback,
23  discovery_info: DiscoveryInfoType | None = None,
24 ) -> None:
25  """Set up Tellstick switches."""
26  if discovery_info is None or discovery_info[ATTR_DISCOVER_DEVICES] is None:
27  return
28 
29  # Allow platform level override, fallback to module config
30  signal_repetitions = discovery_info.get(
31  ATTR_DISCOVER_CONFIG, DEFAULT_SIGNAL_REPETITIONS
32  )
33 
35  [
36  TellstickSwitch(hass.data[DATA_TELLSTICK][tellcore_id], signal_repetitions)
37  for tellcore_id in discovery_info[ATTR_DISCOVER_DEVICES]
38  ],
39  True,
40  )
41 
42 
44  """Representation of a Tellstick switch."""
45 
46  _attr_force_update = True
47 
48  def _parse_ha_data(self, kwargs):
49  """Turn the value from HA into something useful."""
50 
51  def _parse_tellcore_data(self, tellcore_data):
52  """Turn the value received from tellcore into something useful."""
53 
54  def _update_model(self, new_state, data):
55  """Update the device entity state to match the arguments."""
56  self._state_state_state = new_state
57 
58  def _send_device_command(self, requested_state, requested_data):
59  """Let tellcore update the actual device to the requested state."""
60  if requested_state:
61  self._tellcore_device_tellcore_device.turn_on()
62  else:
63  self._tellcore_device_tellcore_device.turn_off()
def _send_device_command(self, requested_state, requested_data)
Definition: switch.py:58
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: switch.py:24