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

Unable to disarm alarm for units that require a `userId` #123

Closed palazzem closed 7 months ago

palazzem commented 7 months ago

Describe the bug The integration is installed and configured without errors. When the alarm is armed, everything works as expected but disarming is not possibile as it returns "selected sectors 1 don't exist" in the logs.

Error message

2024-01-30 23:16:29.441 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140076357337536] Selected sectors don't exist: 1
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 238, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/econnect_metronet/decorators.py", line 26, in func_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/econnect_metronet/alarm_control_panel.py", line 98, in async_alarm_disarm
    await self.hass.async_add_executor_job(self._device.disarm, code)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/econnect_metronet/devices.py", line 296, in disarm
    self._connection.disarm(sectors=sectors)
  File "/usr/local/lib/python3.11/site-packages/elmo/api/decorators.py", line 22, in func_wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/elmo/api/decorators.py", line 52, in func_wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/elmo/api/client.py", line 334, in disarm
    raise InvalidSector("Selected sectors don't exist: {}".format(invalid_sectors))
elmo.api.exceptions.InvalidSector: Selected sectors don't exist: 1

Expected behavior As users can arm the alarm, it's expected they can also disarm it.

Additional context User experiencing this issue has configured the alarm using 2 areas with 4 sectors each. The integration retrieves 8 sectors without distinguishing the areas.

To Reproduce Not reproduced yet locally.

Environment

palazzem commented 7 months ago

After another round of investigation, we discovered that the error is misleading (fixed in #133) as the underlying response error is:

2024-01-30 23:16:28.893 DEBUG (SyncWorker_14) [elmo.api.client] Client | Disarming response: [{'Poller': {'Poller': 1, 'Panel': 1}, 'CommandId': 1, 'Successful': False, 'ErrorMessages': ['Comando fallito totalmente o parzialmente']}]

A possible root cause (thanks @xtimmy86x for the insights!) is that the main unit is a model that still requires the userID as part of the code to obtain the supervision (and so to send commands). In the first call payload (Panel API), there is a field we can use called LoginWithoutUserID. If this field is false, it means that the main unit is expecting a userID, hence the API call should include userID in the payload.

Given this investigation, we may need to:

  1. Update econnect-python to query the Panel API
  2. Store all the details and use LoginWithoutUserID to understand if userID should be sent or not
  3. Let users insert in Home Assistant the code directly from the panel using something like USER_ID*CODE (* is the separator).

Let's take another pass so we can support also these models!