palazzem / ha-econnect-alarm

Home Assistant integration that provides a full-fledged Alarm Panel to control your Elmo/IESS alarm systems.
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

Alarm state moves between states when activated via HomeKit #154

Closed palazzem closed 3 months ago

palazzem commented 3 months ago

Describe the bug The integration changes the alarm state temporarily (a blip) when the state is changed via HomeKit. For instance, when "Arm Home" is activated, the alarm goes temporarily into "Arm Away" and then "Arm Home" after few seconds.

This blip, triggers also unwanted integrations.

Error message None, other than the incorrect behavior.

Expected behavior When a user select an alarm mode (e.g. "Arm Night"), the alarm should go directly to that state.

Additional context It seems happening only while HomeKit, but it may happen also if you change states using the alarm panel without code.

To Reproduce

  1. Set "Disarm" state.
  2. From Homekit, activate "Arm Home".
  3. The alarm goes into "Arm Away" and then "Arm Home" (this is the incorrect behavior).

Environment

palazzem commented 3 months ago

cc @andr3a88 who is impacted by this issue.

palazzem commented 3 months ago

After some investigation, I discovered that the issue happens for two main reasons:

  1. This integration didn't handle some states transitions, causing blips because of race conditions. Issues related to this behavior have been fixed in:
    • 153

    • 155

  2. HomeKit integration maps states between Home Assistant and HomeKit (see code) and at the time of writing it's mapping STATE_ALARM_ARMING with HK_ALARM_AWAY_ARMED. When users activates a given mode (e.g. Arm Home), the integration goes in this state transition:
    • Disarm -> Arming -> Home
    • HomeKit integration translates it in Disarm -> Away -> Home
    • Hence users see the transition Disarm -> Home -> Away -> Home

What can be fixed in the integration has been fixed, but the issue still persist. Further changes should happen in the Home Assistant code base as other developers are trying to fix it (e.g. https://github.com/home-assistant/core/pull/108863).

@andr3a88 I'm moving the conversation in HA repository as the change should happen there.