mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +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 datetime
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -185,6 +186,16 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
A trigger_time of zero disables the alarm_trigger service.
|
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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass,
|
hass,
|
||||||
@ -198,13 +209,13 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
"""Init the manual alarm panel."""
|
"""Init the manual alarm panel."""
|
||||||
self._state = STATE_ALARM_DISARMED
|
self._state = STATE_ALARM_DISARMED
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
if code_template:
|
if code_template:
|
||||||
self._code = code_template
|
self._code = code_template
|
||||||
self._code.hass = hass
|
self._code.hass = hass
|
||||||
else:
|
else:
|
||||||
self._code = code or None
|
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._disarm_after_trigger = disarm_after_trigger
|
||||||
self._previous_state = self._state
|
self._previous_state = self._state
|
||||||
self._state_ts = None
|
self._state_ts = None
|
||||||
@ -222,17 +233,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def state(self) -> str:
|
||||||
"""Return the polling state."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
if self._state == STATE_ALARM_TRIGGERED:
|
if self._state == STATE_ALARM_TRIGGERED:
|
||||||
if self._within_pending_time(self._state):
|
if self._within_pending_time(self._state):
|
||||||
@ -253,18 +254,6 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
|
|
||||||
return self._state
|
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
|
@property
|
||||||
def _active_state(self):
|
def _active_state(self):
|
||||||
"""Get the current state."""
|
"""Get the current state."""
|
||||||
@ -289,7 +278,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
return self._state_ts + self._pending_time(state) > dt_util.utcnow()
|
return self._state_ts + self._pending_time(state) > dt_util.utcnow()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self) -> alarm.CodeFormat | None:
|
||||||
"""Return one or more digits/characters."""
|
"""Return one or more digits/characters."""
|
||||||
if self._code is None:
|
if self._code is None:
|
||||||
return None
|
return None
|
||||||
@ -297,11 +286,6 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
return alarm.CodeFormat.NUMBER
|
return alarm.CodeFormat.NUMBER
|
||||||
return alarm.CodeFormat.TEXT
|
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:
|
def alarm_disarm(self, code: str | None = None) -> None:
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
if not self._validate_code(code, STATE_ALARM_DISARMED):
|
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:
|
def alarm_arm_home(self, code: str | None = None) -> None:
|
||||||
"""Send arm home command."""
|
"""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
|
code, STATE_ALARM_ARMED_HOME
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@ -322,7 +306,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
|
|
||||||
def alarm_arm_away(self, code: str | None = None) -> None:
|
def alarm_arm_away(self, code: str | None = None) -> None:
|
||||||
"""Send arm away command."""
|
"""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
|
code, STATE_ALARM_ARMED_AWAY
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@ -331,7 +315,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
|
|
||||||
def alarm_arm_night(self, code: str | None = None) -> None:
|
def alarm_arm_night(self, code: str | None = None) -> None:
|
||||||
"""Send arm night command."""
|
"""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
|
code, STATE_ALARM_ARMED_NIGHT
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@ -340,7 +324,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
|
|
||||||
def alarm_arm_vacation(self, code: str | None = None) -> None:
|
def alarm_arm_vacation(self, code: str | None = None) -> None:
|
||||||
"""Send arm vacation command."""
|
"""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
|
code, STATE_ALARM_ARMED_VACATION
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@ -349,7 +333,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
|
|
||||||
def alarm_arm_custom_bypass(self, code: str | None = None) -> None:
|
def alarm_arm_custom_bypass(self, code: str | None = None) -> None:
|
||||||
"""Send arm custom bypass command."""
|
"""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
|
code, STATE_ALARM_ARMED_CUSTOM_BYPASS
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@ -367,7 +351,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
return
|
return
|
||||||
self._update_state(STATE_ALARM_TRIGGERED)
|
self._update_state(STATE_ALARM_TRIGGERED)
|
||||||
|
|
||||||
def _update_state(self, state):
|
def _update_state(self, state: str) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
if self._state == state:
|
if self._state == state:
|
||||||
return
|
return
|
||||||
@ -414,7 +398,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||||||
return check
|
return check
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
if self.state in (STATE_ALARM_PENDING, STATE_ALARM_ARMING):
|
if self.state in (STATE_ALARM_PENDING, STATE_ALARM_ARMING):
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user