Skip to content

Commit

Permalink
ensure that retry arming uses last used arm mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsfaber committed May 31, 2024
1 parent dd1adc7 commit 04f7754
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/alarmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ async def async_handle_push_event(event):
_LOGGER.info("Cannot process the push action, since there are multiple areas.")
return

arm_mode = alarm_entity._arm_mode
arm_mode = alarm_entity._revert_state if alarm_entity._revert_state in const.ARM_MODES else alarm_entity._arm_mode
res = re.search(r"^ALARMO_ARM_", action)
if res:
arm_mode = action.replace("ALARMO_", "").lower().replace("arm", "armed")
Expand Down
7 changes: 5 additions & 2 deletions custom_components/alarmo/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ def async_arm_failure(self, open_sensors: dict, context_id=None):
else:
# when disarmed, only update the attributes
if self._revert_state in const.ARM_MODES:
prev_arm_mode = self._arm_mode
self._arm_mode = self._revert_state
self._revert_state = prev_arm_mode

self.schedule_update_ha_state()

Expand Down Expand Up @@ -1043,6 +1045,7 @@ def async_arm(self, arm_mode, **kwargs):
open_sensors = {}
for item in self.hass.data[const.DOMAIN]["areas"].values():
if (item.state in const.ARM_MODES and item.arm_mode != arm_mode) or item.state == STATE_ALARM_DISARMED:
item._revert_state = item._state if item._state in const.ARM_MODES else STATE_ALARM_DISARMED
res = item.async_arm(
arm_mode,
skip_delay=skip_delay,
Expand Down Expand Up @@ -1077,13 +1080,13 @@ def async_arm_failure(self, open_sensors: dict, context_id=None):
"""handle arm failure."""
self.open_sensors = open_sensors
command = self._target_state.replace("armed", "arm")
self._target_state = None

for item in self.hass.data[const.DOMAIN]["areas"].values():
if item.state != self._revert_state and self._revert_state:
item.async_update_state(self._revert_state)

self._revert_state = None
self._revert_state = self._target_state
self._target_state = None
dispatcher_send(
self.hass,
"alarmo_event",
Expand Down

0 comments on commit 04f7754

Please sign in to comment.