Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Velbus switches."""
2 
3 from typing import Any
4 
5 from velbusaio.channels import Relay as VelbusRelay
6 
7 from homeassistant.components.switch import SwitchEntity
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .const import DOMAIN
13 from .entity import VelbusEntity, api_call
14 
15 
17  hass: HomeAssistant,
18  entry: ConfigEntry,
19  async_add_entities: AddEntitiesCallback,
20 ) -> None:
21  """Set up Velbus switch based on config_entry."""
22  await hass.data[DOMAIN][entry.entry_id]["tsk"]
23  cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
24  async_add_entities(VelbusSwitch(channel) for channel in cntrl.get_all("switch"))
25 
26 
28  """Representation of a switch."""
29 
30  _channel: VelbusRelay
31 
32  @property
33  def is_on(self) -> bool:
34  """Return true if the switch is on."""
35  return self._channel_channel.is_on()
36 
37  @api_call
38  async def async_turn_on(self, **kwargs: Any) -> None:
39  """Instruct the switch to turn on."""
40  await self._channel_channel.turn_on()
41 
42  @api_call
43  async def async_turn_off(self, **kwargs: Any) -> None:
44  """Instruct the switch to turn off."""
45  await self._channel_channel.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:20