1 """Support for Tuya Alarm."""
3 from __future__
import annotations
5 from enum
import StrEnum
7 from tuya_sharing
import CustomerDevice, Manager
10 AlarmControlPanelEntity,
11 AlarmControlPanelEntityDescription,
12 AlarmControlPanelEntityFeature,
13 AlarmControlPanelState,
19 from .
import TuyaConfigEntry
20 from .const
import TUYA_DISCOVERY_NEW, DPCode, DPType
21 from .entity
import TuyaEntity
33 STATE_MAPPING: dict[str, AlarmControlPanelState] = {
34 Mode.DISARMED: AlarmControlPanelState.DISARMED,
35 Mode.ARM: AlarmControlPanelState.ARMED_AWAY,
36 Mode.HOME: AlarmControlPanelState.ARMED_HOME,
37 Mode.SOS: AlarmControlPanelState.TRIGGERED,
43 ALARM: dict[str, tuple[AlarmControlPanelEntityDescription, ...]] = {
48 key=DPCode.MASTER_MODE,
56 hass: HomeAssistant, entry: TuyaConfigEntry, async_add_entities: AddEntitiesCallback
58 """Set up Tuya alarm dynamically through Tuya discovery."""
59 hass_data = entry.runtime_data
63 """Discover and add a discovered Tuya siren."""
64 entities: list[TuyaAlarmEntity] = []
65 for device_id
in device_ids:
66 device = hass_data.manager.device_map[device_id]
67 if descriptions := ALARM.get(device.category):
70 for description
in descriptions
71 if description.key
in device.status
77 entry.async_on_unload(
83 """Tuya Alarm Entity."""
86 _attr_code_arm_required =
False
90 device: CustomerDevice,
91 device_manager: Manager,
92 description: AlarmControlPanelEntityDescription,
94 """Init Tuya Alarm."""
95 super().
__init__(device, device_manager)
101 description.key, dptype=DPType.ENUM, prefer_function=
True
103 if Mode.HOME
in supported_modes.range:
104 self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_HOME
106 if Mode.ARM
in supported_modes.range:
107 self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_AWAY
109 if Mode.SOS
in supported_modes.range:
110 self._attr_supported_features |= AlarmControlPanelEntityFeature.TRIGGER
114 """Return the state of the device."""
117 return STATE_MAPPING.get(status)
120 """Send Disarm command."""
126 """Send Home command."""
130 """Send Arm command."""
134 """Send SOS command."""
None alarm_arm_away(self, str|None code=None)
None alarm_disarm(self, str|None code=None)
None __init__(self, CustomerDevice device, Manager device_manager, AlarmControlPanelEntityDescription description)
None alarm_arm_home(self, str|None code=None)
AlarmControlPanelState|None alarm_state(self)
None alarm_trigger(self, str|None code=None)
None _send_command(self, list[dict[str, Any]] commands)
DPCode|EnumTypeData|IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, DPType|None dptype=None)
IntegerTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.INTEGER] dptype)
DPCode|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False)
EnumTypeData|None find_dpcode(self, str|DPCode|tuple[DPCode,...]|None dpcodes, *bool prefer_function=False, Literal[DPType.ENUM] dptype)
ElkSystem|None async_discover_device(HomeAssistant hass, str host)
None async_setup_entry(HomeAssistant hass, TuyaConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)