Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for list index when using NaviLink with multiple units on the same channel #45

Open
tdfountain opened this issue Jan 20, 2025 · 0 comments

Comments

@tdfountain
Copy link

The Navien custom component fails with a list index out of range. The error message in the Home Assistant log shows as:

2025-01-20 13:04:19.267 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback NavilinkConnect.async_handle_channel_status() (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/navien_water_heater/navien_api.py", line 339, 
in async_handle_channel_status
    channel.update_channel_status(channel_status.get("channel",{}))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/navien_water_heater/navien_api.py", line 383, 
in update_channel_status
    self.channel_status = self.convert_channel_status(channel_status)
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/config/custom_components/navien_water_heater/navien_api.py", line 468, 
in convert_channel_status
    channel_status["unitInfo"]["unitStatusList"][i]["gasInstantUsage"] = round(c
hannel_status["unitInfo"]["unitStatusList"][i]["gasInstantUsage"] * GIUFactor * 
3.968, 1)
                                                                               ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

The error points to "[i]".

This configuration has 3 units on channel and 1 unit on channel 2. The failure occurs because the unitCount is returned as 3 (presumably for channel 1), the unitStatusList has only 1 list item at i=0, but lines 468-470 fail when accessing i=1 and i=2. I can avoid the error by continuing the for loop when i is greater than the length of the unitStatusList, but then I see only channel 1 unit 1 and channel 2 unit 1. I am unable to see information for channel 1 unit 2 and unit 3.

I unfortunately have not had a chance to review the Navien API response. It is likely the Navien API implementation is not processing all of the units on the channel and this part of the code assumes unitStatusList has all of the devices.

@tdfountain tdfountain changed the title Error for list index when using NaviLink with multiple channels Error for list index when using NaviLink with multiple units on the same channel Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant