1 """Component providing HA switch support for Ring Door Bell/Chimes."""
3 from collections.abc
import Callable, Coroutine, Sequence
4 from dataclasses
import dataclass
6 from typing
import Any, Generic, Self, cast
8 from ring_doorbell
import RingCapability, RingDoorBell, RingStickUpCam
9 from ring_doorbell.const
import DOORBELL_EXISTING_TYPE
17 from .
import RingConfigEntry
18 from .coordinator
import RingDataCoordinator
23 RingEntityDescription,
24 async_check_create_deprecated,
28 _LOGGER = logging.getLogger(__name__)
30 IN_HOME_CHIME_IS_PRESENT = {v
for k, v
in DOORBELL_EXISTING_TYPE.items()
if k != 2}
33 @dataclass(frozen=True, kw_only=True)
35 SwitchEntityDescription, RingEntityDescription, Generic[RingDeviceT]
37 """Describes a Ring switch entity."""
39 exists_fn: Callable[[RingDeviceT], bool]
40 unique_id_fn: Callable[[Self, RingDeviceT], str] = (
41 lambda self, device: f
"{device.device_api_id}-{self.key}"
43 is_on_fn: Callable[[RingDeviceT], bool]
44 turn_on_fn: Callable[[RingDeviceT], Coroutine[Any, Any,
None]]
45 turn_off_fn: Callable[[RingDeviceT], Coroutine[Any, Any,
None]]
48 SWITCHES: Sequence[RingSwitchEntityDescription[Any]] = (
49 RingSwitchEntityDescription[RingStickUpCam](
51 translation_key=
"siren",
52 exists_fn=
lambda device: device.has_capability(RingCapability.SIREN),
53 is_on_fn=
lambda device: device.siren > 0,
54 turn_on_fn=
lambda device: device.async_set_siren(1),
55 turn_off_fn=
lambda device: device.async_set_siren(0),
57 new_platform=Platform.SIREN, breaks_in_ha_version=
"2025.4.0"
60 RingSwitchEntityDescription[RingDoorBell](
62 translation_key=
"in_home_chime",
63 exists_fn=
lambda device: device.family ==
"doorbots"
64 and device.existing_doorbell_type
in IN_HOME_CHIME_IS_PRESENT,
65 is_on_fn=
lambda device: device.existing_doorbell_type_enabled
or False,
66 turn_on_fn=
lambda device: device.async_set_existing_doorbell_type_enabled(
True),
67 turn_off_fn=
lambda device: device.async_set_existing_doorbell_type_enabled(
71 RingSwitchEntityDescription[RingDoorBell](
72 key=
"motion_detection",
73 translation_key=
"motion_detection",
74 exists_fn=
lambda device: device.has_capability(RingCapability.MOTION_DETECTION),
75 is_on_fn=
lambda device: device.motion_detection,
76 turn_on_fn=
lambda device: device.async_set_motion_detection(
True),
77 turn_off_fn=
lambda device: device.async_set_motion_detection(
False),
84 entry: RingConfigEntry,
85 async_add_entities: AddEntitiesCallback,
87 """Create the switches for the Ring devices."""
88 ring_data = entry.runtime_data
89 devices_coordinator = ring_data.devices_coordinator
92 RingSwitch(device, devices_coordinator, description)
93 for description
in SWITCHES
94 for device
in ring_data.devices.all_devices
95 if description.exists_fn(device)
99 description.unique_id_fn(description, device),
106 """Represents a switch for controlling an aspect of a ring device."""
108 entity_description: RingSwitchEntityDescription[RingDeviceT]
113 coordinator: RingDataCoordinator,
114 description: RingSwitchEntityDescription[RingDeviceT],
116 """Initialize the switch."""
117 super().
__init__(device, coordinator)
125 """Call update method."""
135 """Update switch state, and causes Home Assistant to correctly update."""
145 """Turn the siren on for 30 seconds."""
149 """Turn the siren off."""
RingDevices _get_coordinator_data(self)
None _async_set_switch(self, bool switch_on)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _handle_coordinator_update(self)
None __init__(self, RingDeviceT device, RingDataCoordinator coordinator, RingSwitchEntityDescription[RingDeviceT] description)
None async_write_ha_state(self)
DeviceEntry get_device(HomeAssistant hass, str unique_id)
bool async_check_create_deprecated(HomeAssistant hass, Platform platform, str unique_id, RingEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, RingConfigEntry entry, AddEntitiesCallback async_add_entities)