Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

IndexError: list index out of range #7

Open
timwelchnz opened this issue Jan 29, 2024 · 6 comments
Open

IndexError: list index out of range #7

timwelchnz opened this issue Jan 29, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@timwelchnz
Copy link

Hi there,

I've added your add-one via HACs and fired it up. Unfortunately it doesn't appear to start correctly but rather logs the following..

contact_energy: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 573, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1218, in async_device_update
await hass.async_add_executor_job(self.update)
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/contact_energy/sensor.py", line 147, in update
if self._api.login() == False:
^^^^^^^^^^^^^^^^^
File "/config/custom_components/contact_energy/api.py", line 35, in login
self.refresh_session()
File "/config/custom_components/contact_energy/api.py", line 57, in refresh_session
self.get_accounts()
File "/config/custom_components/contact_energy/api.py", line 75, in get_accounts
self._contractId = data['accounts'][0]['contracts'][0]['contractId']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Any idea what might be causing this? More than happy to assist troubleshooting.

Cheers, Tim

@timwelchnz
Copy link
Author

FYI: I'm not a coder but know enough to be dangerous.
I did some digging within api.py and added _LOGGER.debug(data) to find out what was being returned.

I found that my account returns 3 accounts; 2 of which are cancelled because we used to have gas with Contact but don't anymore.

'accounts': [
{'id': '501001420',
'nickname': '',
'status': 'CANCELLED',
'contracts': []},
{'id': '501001424',
'nickname': '',
'status': 'CANCELLED',
'contracts': []},
{'id': '501131230',
'nickname': '',
'status': 'ACTIVE',
'contracts': [{'contractId': '13xxxxx

So I changed line 74 and 75 (on my local instance) to the following...

        self._accountId = data['accounts'][2]['id']
        self._contractId = data['accounts'][2]['contracts'][0]['contractId']

So now it logs in but no data is returned...

2024-01-30 07:01:07.833 DEBUG (SyncWorker_8) [custom_components.contact_energy.sensor] Beginning usage update
2024-01-30 07:01:07.833 DEBUG (SyncWorker_8) [custom_components.contact_energy.sensor] We appear to be logged in (lets not verify it for now)
2024-01-30 07:01:07.834 DEBUG (SyncWorker_8) [custom_components.contact_energy.sensor] Fetching usage data
2024-01-30 07:01:09.317 ERROR (SyncWorker_8) [custom_components.contact_energy.api] Failed to fetch usage data for 2024/1/20
2024-01-30 07:01:09.318 DEBUG (SyncWorker_8) [custom_components.contact_energy.api] <Response [502]>
2024-01-30 07:01:10.373 ERROR (SyncWorker_8) [custom_components.contact_energy.api] Failed to fetch usage data for 2024/1/21
2024-01-30 07:01:10.373 DEBUG (SyncWorker_8) [custom_components.contact_energy.api] <Response [502]>
2024-01-30 07:01:12.013 ERROR (SyncWorker_8) [custom_components.contact_energy.api] Failed to fetch usage data for 2024/1/22
2024-01-30 07:01:12.013 DEBUG (SyncWorker_8) [custom_components.contact_energy.api] <Response [502]>

At this point I'm well out of my depth!

Cheers, Tim

@codyc1515 codyc1515 self-assigned this Jan 30, 2024
@codyc1515 codyc1515 added the bug Something isn't working label Jan 30, 2024
@codyc1515
Copy link
Owner

Hmm, that's an interesting one. Could you please try turn on debug logging on the integration page? Example below is Meridian but it looks the same. Then hit the three-dots and reload? Wait maybe 10 seconds then turn off debug logs and upload them here.

image

@ciscorustynz
Copy link

Hi,

I am also not getting any data back. However I am not able to add the Integration to turn on debugging due to the message below:

image

I have added my details to the configuration.yaml file and I can see the sensors under the energy panel. Am I doing something wrong?

@codyc1515
Copy link
Owner

Ah sorry that’s right. This integration does not have a config flow. I will need to do a serious rewrite. Let me get back to you on this.

@timwelchnz
Copy link
Author

If it helps I've been playing around with the API today in PowerShell and stumbled upon this where he pulls the account information from a different endpoint.

If I access my account information at /accounts/v2 then none of the above "cancelled" accounts get pulled.

@leemurphy1977
Copy link

Did anything ever come of this? I have Electricity and Gas with Contact, and at todays prices it'd be great if I could have this information in HA :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants