Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Switch support for the Skybell HD Doorbell."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, cast
6 
7 from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
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 SkybellEntity
14 
15 SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
17  key="do_not_disturb",
18  translation_key="do_not_disturb",
19  ),
21  key="do_not_ring",
22  translation_key="do_not_ring",
23  ),
25  key="motion_sensor",
26  translation_key="motion_sensor",
27  ),
28 )
29 
30 
32  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
33 ) -> None:
34  """Set up the SkyBell switch."""
36  SkybellSwitch(coordinator, description)
37  for coordinator in hass.data[DOMAIN][entry.entry_id]
38  for description in SWITCH_TYPES
39  )
40 
41 
43  """A switch implementation for Skybell devices."""
44 
45  async def async_turn_on(self, **kwargs: Any) -> None:
46  """Turn on the switch."""
47  await self._device_device.async_set_setting(self.entity_descriptionentity_description.key, True)
48 
49  async def async_turn_off(self, **kwargs: Any) -> None:
50  """Turn off the switch."""
51  await self._device_device.async_set_setting(self.entity_descriptionentity_description.key, False)
52 
53  @property
54  def is_on(self) -> bool:
55  """Return true if entity is on."""
56  return cast(bool, getattr(self._device_device, self.entity_descriptionentity_description.key))
None async_turn_off(self, **Any kwargs)
Definition: entity.py:1709
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:33