mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
merge requires_code and code_format properties
This commit is contained in:
parent
e29deb0202
commit
cdc371c3ee
@ -97,14 +97,9 @@ def alarm_arm_away(hass, code, entity_id=None):
|
|||||||
class AlarmControlPanel(Entity):
|
class AlarmControlPanel(Entity):
|
||||||
""" ABC for alarm control devices. """
|
""" ABC for alarm control devices. """
|
||||||
|
|
||||||
@property
|
|
||||||
def requires_code(self):
|
|
||||||
""" Boolean if alarm requires a code """
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
""" regex for code format """
|
""" regex for code format or None if no code is required """
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
|
@ -138,19 +138,14 @@ class MqttAlarm(alarm.AlarmControlPanel):
|
|||||||
""" Returns the state of the device. """
|
""" Returns the state of the device. """
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
|
||||||
def requires_code(self):
|
|
||||||
""" code is required if it's defined in configuration file """
|
|
||||||
return self._code is not None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
""" One or more characters """
|
""" One or more characters if code is defined """
|
||||||
return '.+'
|
return None if self._code is None else '.+'
|
||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
""" Send disarm command. """
|
""" Send disarm command. """
|
||||||
if code == str(self._code) or not self.requires_code:
|
if code == str(self._code) or self.code_format is None:
|
||||||
mqtt.publish(self.hass, self._command_topic,
|
mqtt.publish(self.hass, self._command_topic,
|
||||||
self._payload_disarm, self._qos)
|
self._payload_disarm, self._qos)
|
||||||
else:
|
else:
|
||||||
@ -158,7 +153,7 @@ class MqttAlarm(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
def alarm_arm_home(self, code=None):
|
||||||
""" Send arm home command. """
|
""" Send arm home command. """
|
||||||
if code == str(self._code) or not self.requires_code:
|
if code == str(self._code) or self.code_format is None:
|
||||||
mqtt.publish(self.hass, self._command_topic,
|
mqtt.publish(self.hass, self._command_topic,
|
||||||
self._payload_arm_home, self._qos)
|
self._payload_arm_home, self._qos)
|
||||||
else:
|
else:
|
||||||
@ -166,7 +161,7 @@ class MqttAlarm(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
def alarm_arm_away(self, code=None):
|
||||||
""" Send arm away command. """
|
""" Send arm away command. """
|
||||||
if code == str(self._code) or not self.requires_code:
|
if code == str(self._code) or self.code_format is None:
|
||||||
mqtt.publish(self.hass, self._command_topic,
|
mqtt.publish(self.hass, self._command_topic,
|
||||||
self._payload_arm_away, self._qos)
|
self._payload_arm_away, self._qos)
|
||||||
else:
|
else:
|
||||||
|
@ -51,14 +51,9 @@ class VerisureAlarm(alarm.AlarmControlPanel):
|
|||||||
""" Returns the state of the device. """
|
""" Returns the state of the device. """
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
|
||||||
def requires_code(self):
|
|
||||||
""" code is required """
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
""" Four digit code """
|
""" Four digit code required"""
|
||||||
return '[0-9]{4}'
|
return '[0-9]{4}'
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user