mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Improve type hints in mqtt and template alarms (#74101)
This commit is contained in:
parent
2a0b2ecca1
commit
dac8f242e0
@ -172,7 +172,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||||||
|
|
||||||
def __init__(self, hass, config, config_entry, discovery_data):
|
def __init__(self, hass, config, config_entry, discovery_data):
|
||||||
"""Init the MQTT Alarm Control Panel."""
|
"""Init the MQTT Alarm Control Panel."""
|
||||||
self._state = None
|
self._state: str | None = None
|
||||||
|
|
||||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||||||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str | None:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@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 (code := self._config.get(CONF_CODE)) is None:
|
if (code := self._config.get(CONF_CODE)) is None:
|
||||||
return None
|
return None
|
||||||
@ -259,10 +259,9 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||||||
return alarm.CodeFormat.TEXT
|
return alarm.CodeFormat.TEXT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_arm_required(self):
|
def code_arm_required(self) -> bool:
|
||||||
"""Whether the code is required for arm actions."""
|
"""Whether the code is required for arm actions."""
|
||||||
code_required = self._config.get(CONF_CODE_ARM_REQUIRED)
|
return self._config[CONF_CODE_ARM_REQUIRED]
|
||||||
return code_required
|
|
||||||
|
|
||||||
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
||||||
"""Send disarm command.
|
"""Send disarm command.
|
||||||
|
@ -144,8 +144,8 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||||||
name = self._attr_name
|
name = self._attr_name
|
||||||
self._template = config.get(CONF_VALUE_TEMPLATE)
|
self._template = config.get(CONF_VALUE_TEMPLATE)
|
||||||
self._disarm_script = None
|
self._disarm_script = None
|
||||||
self._code_arm_required = config[CONF_CODE_ARM_REQUIRED]
|
self._code_arm_required: bool = config[CONF_CODE_ARM_REQUIRED]
|
||||||
self._code_format = config[CONF_CODE_FORMAT]
|
self._code_format: TemplateCodeFormat = config[CONF_CODE_FORMAT]
|
||||||
if (disarm_action := config.get(CONF_DISARM_ACTION)) is not None:
|
if (disarm_action := config.get(CONF_DISARM_ACTION)) is not None:
|
||||||
self._disarm_script = Script(hass, disarm_action, name, DOMAIN)
|
self._disarm_script = Script(hass, disarm_action, name, DOMAIN)
|
||||||
self._arm_away_script = None
|
self._arm_away_script = None
|
||||||
@ -158,10 +158,10 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||||||
if (arm_night_action := config.get(CONF_ARM_NIGHT_ACTION)) is not None:
|
if (arm_night_action := config.get(CONF_ARM_NIGHT_ACTION)) is not None:
|
||||||
self._arm_night_script = Script(hass, arm_night_action, name, DOMAIN)
|
self._arm_night_script = Script(hass, arm_night_action, name, DOMAIN)
|
||||||
|
|
||||||
self._state = None
|
self._state: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str | None:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@ -187,12 +187,12 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||||||
return supported_features
|
return supported_features
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self) -> CodeFormat | None:
|
||||||
"""Regex for code format or None if no code is required."""
|
"""Regex for code format or None if no code is required."""
|
||||||
return self._code_format.value
|
return self._code_format.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_arm_required(self):
|
def code_arm_required(self) -> bool:
|
||||||
"""Whether the code is required for arm actions."""
|
"""Whether the code is required for arm actions."""
|
||||||
return self._code_arm_required
|
return self._code_arm_required
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user