Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for the for Danfoss Air HRV sswitches."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 from pydanfossair.commands import ReadCommand, UpdateCommand
9 
10 from homeassistant.components.switch import SwitchEntity
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
14 
15 from . import DOMAIN as DANFOSS_AIR_DOMAIN
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 
21  hass: HomeAssistant,
22  config: ConfigType,
23  add_entities: AddEntitiesCallback,
24  discovery_info: DiscoveryInfoType | None = None,
25 ) -> None:
26  """Set up the Danfoss Air HRV switch platform."""
27  data = hass.data[DANFOSS_AIR_DOMAIN]
28 
29  switches = [
30  [
31  "Danfoss Air Boost",
32  ReadCommand.boost,
33  UpdateCommand.boost_activate,
34  UpdateCommand.boost_deactivate,
35  ],
36  [
37  "Danfoss Air Bypass",
38  ReadCommand.bypass,
39  UpdateCommand.bypass_activate,
40  UpdateCommand.bypass_deactivate,
41  ],
42  [
43  "Danfoss Air Automatic Bypass",
44  ReadCommand.automatic_bypass,
45  UpdateCommand.bypass_activate,
46  UpdateCommand.bypass_deactivate,
47  ],
48  ]
49 
51  DanfossAir(data, switch[0], switch[1], switch[2], switch[3])
52  for switch in switches
53  )
54 
55 
57  """Representation of a Danfoss Air HRV Switch."""
58 
59  def __init__(self, data, name, state_command, on_command, off_command):
60  """Initialize the switch."""
61  self._data_data = data
62  self._name_name = name
63  self._state_command_state_command = state_command
64  self._on_command_on_command = on_command
65  self._off_command_off_command = off_command
66  self._state_state = None
67 
68  @property
69  def name(self):
70  """Return the name of the switch."""
71  return self._name_name
72 
73  @property
74  def is_on(self):
75  """Return true if switch is on."""
76  return self._state_state
77 
78  def turn_on(self, **kwargs: Any) -> None:
79  """Turn the switch on."""
80  _LOGGER.debug("Turning on switch with command %s", self._on_command_on_command)
81  self._data_data.update_state(self._on_command_on_command, self._state_command_state_command)
82 
83  def turn_off(self, **kwargs: Any) -> None:
84  """Turn the switch off."""
85  _LOGGER.debug("Turning off switch with command %s", self._off_command_off_command)
86  self._data_data.update_state(self._off_command_off_command, self._state_command_state_command)
87 
88  def update(self) -> None:
89  """Update the switch's state."""
90  self._data_data.update()
91 
92  self._state_state = self._data_data.get_value(self._state_command_state_command)
93  if self._state_state is None:
94  _LOGGER.debug("Could not get data for %s", self._state_command_state_command)
def __init__(self, data, name, state_command, on_command, off_command)
Definition: switch.py:59
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:25
float|int|str|None get_value(Sensor sensor, str field)
Definition: sensor.py:46