mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use attributes in manual_mqtt alarm (#74124)
This commit is contained in:
parent
a8349a4866
commit
e0d2344db3
@ -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
|
||||||
|
|
||||||
@ -204,6 +205,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
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 = (
|
_attr_supported_features = (
|
||||||
AlarmControlPanelEntityFeature.ARM_HOME
|
AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
@ -231,7 +233,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
"""Init the manual MQTT alarm panel."""
|
"""Init the manual MQTT 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
|
||||||
@ -257,24 +259,14 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
self._state_topic = state_topic
|
self._state_topic = state_topic
|
||||||
self._command_topic = command_topic
|
self._command_topic = command_topic
|
||||||
self._qos = qos
|
self._qos = qos
|
||||||
self._code_arm_required = code_arm_required
|
self._attr_code_arm_required = code_arm_required
|
||||||
self._payload_disarm = payload_disarm
|
self._payload_disarm = payload_disarm
|
||||||
self._payload_arm_home = payload_arm_home
|
self._payload_arm_home = payload_arm_home
|
||||||
self._payload_arm_away = payload_arm_away
|
self._payload_arm_away = payload_arm_away
|
||||||
self._payload_arm_night = payload_arm_night
|
self._payload_arm_night = payload_arm_night
|
||||||
|
|
||||||
@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):
|
||||||
@ -314,7 +306,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
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
|
||||||
@ -322,11 +314,6 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
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):
|
||||||
@ -338,7 +325,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
|
|
||||||
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
|
||||||
@ -347,7 +334,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
|
|
||||||
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
|
||||||
@ -356,7 +343,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
|
|
||||||
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
|
||||||
@ -417,7 +404,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
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 != STATE_ALARM_PENDING:
|
if self.state != STATE_ALARM_PENDING:
|
||||||
return {}
|
return {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user