crserran / home-alarm

Alexa & Google Home alarm integrations and notifications system for your home security.
https://crserran.github.io/home-alarm
MIT License
22 stars 6 forks source link

Alarm triggers when disarming and arming the alarm again #16

Closed xaviml closed 1 year ago

xaviml commented 1 year ago

Bug description

The alarm triggers when it is disarmed and armed again within the activation_delay window. How to reproduce:

Actual: After doing that, the alarm will be triggered. Expected: The alarm should not be triggered since it was disarmed and armed again.

Fix

The problem is that the countdown for the activation_delay timer does not have a cancelation policy. This timer should be always canceled when the alarm is disarmed.

Notes

I have also refactored some code to always use self.safe_mode_active rather than the check await self.get_state(self.safe_mode) == Generic.ON. It is better to be consistent and use the self.safe_mode_active since it is controlled based on safe_mode_delay value. This was not causing directly the issue, but it could potentially affect other corner cases. For this reason, it is better to be consistent and use always self.safe_mode_active.

crserran commented 1 year ago

I have been able to reproduce your issue.

It happens when the safe_mode is activated and you activate a door sensor, next you deactivate the safe_mode and activate it back within the activation_delaytimer.

This PR solves the issue. Thanks @xaviml for your contribution