mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use attributes in manual alarm (#74122)
This commit is contained in:
parent
0769b33e19
commit
6dc6e71f01
@ -5,6 +5,7 @@ import copy
|
||||
import datetime
|
||||
import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -185,6 +186,16 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
A trigger_time of zero disables the alarm_trigger service.
|
||||
"""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||
| AlarmControlPanelEntityFeature.ARM_VACATION
|
||||
| AlarmControlPanelEntityFeature.TRIGGER
|
||||
| AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass,
|
||||
@ -198,13 +209,13 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
"""Init the manual alarm panel."""
|
||||
self._state = STATE_ALARM_DISARMED
|
||||
self._hass = hass
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
if code_template:
|
||||
self._code = code_template
|
||||
self._code.hass = hass
|
||||
else:
|
||||
self._code = code or None
|
||||
self._code_arm_required = code_arm_required
|
||||
self._attr_code_arm_required = code_arm_required
|
||||
self._disarm_after_trigger = disarm_after_trigger
|
||||
self._previous_state = self._state
|
||||
self._state_ts = None
|
||||
@ -222,17 +233,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str:
|
||||
"""Return the state of the device."""
|
||||
if self._state == STATE_ALARM_TRIGGERED:
|
||||
if self._within_pending_time(self._state):
|
||||
@ -253,18 +254,6 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
return (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||
| AlarmControlPanelEntityFeature.ARM_VACATION
|
||||
| AlarmControlPanelEntityFeature.TRIGGER
|
||||
| AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||
)
|
||||
|
||||
@property
|
||||
def _active_state(self):
|
||||
"""Get the current state."""
|
||||
@ -289,7 +278,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
return self._state_ts + self._pending_time(state) > dt_util.utcnow()
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
def code_format(self) -> alarm.CodeFormat | None:
|
||||
"""Return one or more digits/characters."""
|
||||
if self._code is None:
|
||||
return None
|
||||
@ -297,11 +286,6 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
"""Whether the code is required for arm actions."""
|
||||
return self._code_arm_required
|
||||
|
||||
def alarm_disarm(self, code: str | None = None) -> None:
|
||||
"""Send disarm command."""
|
||||
if not self._validate_code(code, STATE_ALARM_DISARMED):
|
||||
@ -313,7 +297,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
def alarm_arm_home(self, code: str | None = None) -> None:
|
||||
"""Send arm home command."""
|
||||
if self._code_arm_required and not self._validate_code(
|
||||
if self.code_arm_required and not self._validate_code(
|
||||
code, STATE_ALARM_ARMED_HOME
|
||||
):
|
||||
return
|
||||
@ -322,7 +306,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
def alarm_arm_away(self, code: str | None = None) -> None:
|
||||
"""Send arm away command."""
|
||||
if self._code_arm_required and not self._validate_code(
|
||||
if self.code_arm_required and not self._validate_code(
|
||||
code, STATE_ALARM_ARMED_AWAY
|
||||
):
|
||||
return
|
||||
@ -331,7 +315,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
def alarm_arm_night(self, code: str | None = None) -> None:
|
||||
"""Send arm night command."""
|
||||
if self._code_arm_required and not self._validate_code(
|
||||
if self.code_arm_required and not self._validate_code(
|
||||
code, STATE_ALARM_ARMED_NIGHT
|
||||
):
|
||||
return
|
||||
@ -340,7 +324,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
def alarm_arm_vacation(self, code: str | None = None) -> None:
|
||||
"""Send arm vacation command."""
|
||||
if self._code_arm_required and not self._validate_code(
|
||||
if self.code_arm_required and not self._validate_code(
|
||||
code, STATE_ALARM_ARMED_VACATION
|
||||
):
|
||||
return
|
||||
@ -349,7 +333,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
|
||||
def alarm_arm_custom_bypass(self, code: str | None = None) -> None:
|
||||
"""Send arm custom bypass command."""
|
||||
if self._code_arm_required and not self._validate_code(
|
||||
if self.code_arm_required and not self._validate_code(
|
||||
code, STATE_ALARM_ARMED_CUSTOM_BYPASS
|
||||
):
|
||||
return
|
||||
@ -367,7 +351,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
return
|
||||
self._update_state(STATE_ALARM_TRIGGERED)
|
||||
|
||||
def _update_state(self, state):
|
||||
def _update_state(self, state: str) -> None:
|
||||
"""Update the state."""
|
||||
if self._state == state:
|
||||
return
|
||||
@ -414,7 +398,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
||||
return check
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the state attributes."""
|
||||
if self.state in (STATE_ALARM_PENDING, STATE_ALARM_ARMING):
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user