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

Duke Energy integration failing with IndexError: list index out of range #134102

Open
cmamatey opened this issue Dec 27, 2024 · 3 comments
Open

Comments

@cmamatey
Copy link

The problem

When this integration was first released, I was receiving same or similar message to what I have shared in the logs section and the integration would fail to initialize. Specifically, I know I was receiving the list index out of range error as part of my failure. At the time (early October?), there were 2 active Duke accounts associated with my duke-energy.com login; 1 was many years old while the other was very new (started service in late September).

Eventually, the integration finally began working correctly on its own without any intervention on my part. I believe this issue resolved around the time that the newer of the 2 Duke accounts was changed to Closed on the Duke website (after I cancelled the home purchase and stopped service at that address). I imagine it could either be due to there being only 1 active account or due to the newly closed account's first billing cycle completing and first statement generating.

The integration continued to function fine until very recently (12/20 or 12/21) when I started service at yet another address and began receiving log errors that are the same or at least very similar to those from October. I have shared the current log errors in the logs section of this Issue submission.
I also see another user's comment in #128414 includes what appear to be the same error logs: https://github.com/home-assistant/core/issues/128414#issuecomment-2555504884

Again, I suspect that either the existence of more than 1 active account on a Duke Energy login or the fact that 1 of the 2 accounts is a newly started service (i.e. yet to complete one billing cycle) is causing the issue.
I am guessing that my problem will go away in the next month or so... either when the first statement is generated for this latest account or when I finally stop service at my old address. In the meantime, please let me know if you need me to provide any sample data from my Duke Energy account(s) while they are still in the failure state.

What version of Home Assistant Core has the issue?

core-2024.12.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Duke Energy

Link to integration documentation on our website

https://www.home-assistant.io/integrations/duke_energy

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.duke_energy.coordinator
Source: helpers/update_coordinator.py:379
integration: Duke Energy (documentation, issues)
First occurred: December 21, 2024 at 10:56:06 AM (25 occurrences)
Last logged: 12:08:40 PM

Unexpected error fetching Duke Energy data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 379, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/duke_energy/coordinator.py", line 101, in _async_update_data
    usage = await self._async_get_energy_usage(meter)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/duke_energy/coordinator.py", line 202, in _async_get_energy_usage
    results = await self.api.get_energy_usage(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        meter["serialNum"], "HOURLY", "DAY", start_step, end_step
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/aiodukeenergy/dukeenergy.py", line 227, in get_energy_usage
    if result["TickSeries"][n] != expected_series:
       ~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Additional information

No response

@home-assistant
Copy link

Hey there @hunterjm, mind taking a look at this issue as it has been labeled with an integration (duke_energy) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of duke_energy can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign duke_energy Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


duke_energy documentation
duke_energy source
(message by IssueLinks)

@cmamatey cmamatey changed the title Duke Energy integration failing when multiple accounts/meters are Active and one is a newly started service Duke Energy integration failing with IndexError: list index out of range Dec 27, 2024
@cmamatey
Copy link
Author

Debug logging adds a little but not much:

2024-12-27 15:08:52.711 DEBUG (MainThread) [homeassistant.components.duke_energy.coordinator] Updating Statistics for duke_energy:electric_<redacted>_energy_consumption
2024-12-27 15:08:52.714 DEBUG (MainThread) [homeassistant.components.duke_energy.coordinator] Updating statistic for the first time
2024-12-27 15:08:52.715 DEBUG (MainThread) [homeassistant.components.duke_energy.coordinator] Data lookup range: 2024-12-20 00:00:00-05:00 - 2024-12-26 00:00:00-05:00
2024-12-27 15:08:52.715 DEBUG (MainThread) [homeassistant.components.duke_energy.coordinator] Getting hourly usage: 2024-11-26 00:00:00-05:00 - 2024-12-26 00:00:00-05:00
2024-12-27 15:08:53.407 ERROR (MainThread) [homeassistant.components.duke_energy.coordinator] Unexpected error fetching Duke Energy data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 379, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/duke_energy/coordinator.py", line 101, in _async_update_data
    usage = await self._async_get_energy_usage(meter)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/duke_energy/coordinator.py", line 202, in _async_get_energy_usage
    results = await self.api.get_energy_usage(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        meter["serialNum"], "HOURLY", "DAY", start_step, end_step
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/aiodukeenergy/dukeenergy.py", line 227, in get_energy_usage
    if result["TickSeries"][n] != expected_series:
       ~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
2024-12-27 15:08:53.409 DEBUG (MainThread) [homeassistant.components.duke_energy.coordinator] Finished fetching Duke Energy data in 6.862 seconds (success: False)

It's worth mentioning that I am only seeing the new meter number mentioned in the logs.
I notice that the debug message for Getting hourly usage is giving a larger date range than there is currently data for this new meter.
I lean towards the issue likely being related to incomplete data returned for the new meter since it does not have a complete month of historical data yet.

@cmamatey
Copy link
Author

I did a brief trace of the code and am wondering if a simple change of line 195 could solve this.
https://github.com/home-assistant/core/blob/dev/homeassistant/components/duke_energy/coordinator.py#L195
Something like:

        start_step = max(end - lookback, start)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants