rainepretorius / olarm-ha-integration

Integration for Olarm devices created by a BSC(Computer Science and Mathematics) student.
https://raine.pretoriusse.net
BSD 2-Clause "Simplified" License
30 stars 13 forks source link

Exception "list index out of range" when retrieving zones labels and bypass states #18

Closed jonathankretzmer closed 1 year ago

jonathankretzmer commented 1 year ago

The returned olarm_zones["zonesLimit"] does not accurately match the number of returned values in olarm_zones["zonesLabels"]

2023-04-05 08:43:09.690 ERROR (MainThread) [custom_components.olarm_sensors.coordinator] Unexpected error fetching Olarm Coordinator (8edcd590-a19b-42d3-b6b3-a0fa6f484b65) data: list index out of range
 Traceback (most recent call last):
   File "/usr/lib/python3.10/site-packages/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh
     self.data = await self._async_update_data()
   File "/config/custom_components/olarm_sensors/coordinator.py", line 134, in _async_update_data
     return await self.update_data()
   File "/config/custom_components/olarm_sensors/coordinator.py", line 98, in update_data
     self.data = await self.api.get_sensor_states(devices_json)
   File "/config/custom_components/olarm_sensors/olarm_api.py", line 119, in get_sensor_states
     olarm_zones["zonesLabels"][zone]
 IndexError: list index out of range

Whilst the iteration makes use of the olarm_zones["zonesLimit"], this value differs from the number of returned values in the array. Perhaps this is an Evo192 panel nuance?

The fix needs to be applied to both the following methods:

Here is the code snippet:

                if (
                    zone < len(olarm_zones["zonesLabels"]) # <-- here is the additional check to make sure we don't receive the exception
                    and (olarm_zones["zonesLabels"][zone] or olarm_zones["zonesLabels"][zone] == "")
                ):
                    zone_name = olarm_zones["zonesLabels"][zone]
rainepretorius commented 1 year ago

Hi @jonathankretzmer,

I added the fix for it just now. Can you please update and let me know if it is working?

jonathankretzmer commented 1 year ago

I see the bugfix was done to the get_sensor_states method, but also needed to be done to the get_sensor_bypass_states method.

Also, there appears to be a new bug with the zone_types now too. I'll pop a quick PR through for you to review as I debugged it to get it working on my local installation anyway.

rainepretorius commented 1 year ago

THanks @jonathankretzmer

jonathankretzmer commented 1 year ago

Pleasure, happy to contribute 🙂

rainepretorius commented 1 year ago

Hi @jonathankretzmer,

Is the new update (1.1.8) working on your side?

jonathankretzmer commented 1 year ago

This particular issue is resolved.

However, I did receive an error related to the introduction of the Pin parameter and that it was missing; removing and then re-adding the integration fixed that.

2023-04-06 09:36:15.053 ERROR (MainThread) [homeassistant.components.alarm_control_panel] Error while setting up olarm_sensors platform for alarm_control_panel
 Traceback (most recent call last):
   File "/usr/lib/python3.10/site-packages/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
     await asyncio.shield(task)
   File "/config/custom_components/olarm_sensors/alarm_control_panel.py", line 43, in async_setup_entry
     sensor = OlarmAlarm(
   File "/config/custom_components/olarm_sensors/alarm_control_panel.py", line 83, in __init__
     if not self.coordinator.entry.data[CONF_ALARM_CODE] is None:
 KeyError: 'olarm_arm_code'
rainepretorius commented 1 year ago

Ok Cool. Yes, according to the release notes, the integration needs to be set up again due to the alarm panel code parameter. I am still looking for a way to add the ability to edit the configuration on the fly without having to redo the setup every time. Please note that the sensor names and entity ids have changed due to adding support for multiple olarm devices. Just in case someone has two different alarms with the same zone name in one of them.