Improve type hints in mqtt and template alarms (#74101)
This commit is contained in:
parent
2a0b2ecca1
commit
dac8f242e0
2 changed files with 11 additions and 12 deletions
|
@ -172,7 +172,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Init the MQTT Alarm Control Panel."""
|
||||
self._state = None
|
||||
self._state: str | None = None
|
||||
|
||||
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)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
|
@ -250,7 +250,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
def code_format(self) -> alarm.CodeFormat | None:
|
||||
"""Return one or more digits/characters."""
|
||||
if (code := self._config.get(CONF_CODE)) is None:
|
||||
return None
|
||||
|
@ -259,10 +259,9 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
return alarm.CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
def code_arm_required(self) -> bool:
|
||||
"""Whether the code is required for arm actions."""
|
||||
code_required = self._config.get(CONF_CODE_ARM_REQUIRED)
|
||||
return code_required
|
||||
return self._config[CONF_CODE_ARM_REQUIRED]
|
||||
|
||||
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
||||
"""Send disarm command.
|
||||
|
|
|
@ -144,8 +144,8 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||
name = self._attr_name
|
||||
self._template = config.get(CONF_VALUE_TEMPLATE)
|
||||
self._disarm_script = None
|
||||
self._code_arm_required = config[CONF_CODE_ARM_REQUIRED]
|
||||
self._code_format = config[CONF_CODE_FORMAT]
|
||||
self._code_arm_required: bool = config[CONF_CODE_ARM_REQUIRED]
|
||||
self._code_format: TemplateCodeFormat = config[CONF_CODE_FORMAT]
|
||||
if (disarm_action := config.get(CONF_DISARM_ACTION)) is not None:
|
||||
self._disarm_script = Script(hass, disarm_action, name, DOMAIN)
|
||||
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:
|
||||
self._arm_night_script = Script(hass, arm_night_action, name, DOMAIN)
|
||||
|
||||
self._state = None
|
||||
self._state: str | None = None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
|
@ -187,12 +187,12 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||
return supported_features
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
def code_format(self) -> CodeFormat | None:
|
||||
"""Regex for code format or None if no code is required."""
|
||||
return self._code_format.value
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
def code_arm_required(self) -> bool:
|
||||
"""Whether the code is required for arm actions."""
|
||||
return self._code_arm_required
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue