Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Duotecno switches."""
2 
3 from typing import Any
4 
5 from duotecno.controller import PyDuotecno
6 from duotecno.unit import SwitchUnit
7 
8 from homeassistant.components.switch import SwitchEntity
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 
13 from .const import DOMAIN
14 from .entity import DuotecnoEntity, api_call
15 
16 
18  hass: HomeAssistant,
19  entry: ConfigEntry,
20  async_add_entities: AddEntitiesCallback,
21 ) -> None:
22  """Set up Velbus switch based on config_entry."""
23  cntrl: PyDuotecno = hass.data[DOMAIN][entry.entry_id]
25  DuotecnoSwitch(channel) for channel in cntrl.get_units("SwitchUnit")
26  )
27 
28 
30  """Representation of a switch."""
31 
32  _unit: SwitchUnit
33 
34  @property
35  def is_on(self) -> bool:
36  """Return true if the switch is on."""
37  return self._unit_unit.is_on()
38 
39  @api_call
40  async def async_turn_on(self, **kwargs: Any) -> None:
41  """Instruct the switch to turn on."""
42  await self._unit_unit.turn_on()
43 
44  @api_call
45  async def async_turn_off(self, **kwargs: Any) -> None:
46  """Instruct the switch to turn off."""
47  await self._unit_unit.turn_off()
None turn_off(self, **Any kwargs)
Definition: entity.py:1705
None turn_on(self, **Any kwargs)
Definition: entity.py:1697
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:21