carohauta / oma-helen-ha-integration

Home Assistant integration for Oma Helen data
MIT License
35 stars 6 forks source link

Error for EXCHANGE type electricity after recent update #2

Closed lakofsth closed 1 year ago

lakofsth commented 1 year ago

Logger: homeassistant.components.sensor Source: custom_components/helen_energy/sensor.py:320 Integration: Sensor (documentation, issues) First occurred: 11:39:24 (1 occurrences) Last logged: 11:39:24 helen_energy: Error on device update!

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 503, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 729, in async_device_update await task File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/helen_energy/sensor.py", line 320, in update self._api_client.calculate_total_costs_by_spot_prices_between_dates( File "/usr/local/lib/python3.10/site-packages/helenservice/api_client.py", line 67, in calculate_total_costs_by_spot_prices_between_dates hourly_consumption_costs = self._get_hourly_consumption_costs(start_date, end_date) File "/usr/local/lib/python3.10/site-packages/helenservice/api_client.py", line 49, in _get_hourly_consumption_costs hourly_measurements = self.get_hourly_measurements_between_dates(start_date, end_date).intervals.electricity[0].measurements IndexError: list index out of range

Home Assistant 2023.1.4 Supervisor 2022.12.1 Operating System 9.4 Frontend 20230110.0 - latest

Helen current month consumption is "unknown"

My contract for Exchange electricity started 15.1 - if that's related I can just wait for the beginning of the next month if needed. I'm happy to gather whatever information you may need to look at this. Thanks!

carohauta commented 1 year ago

There are probably no measurement records yet available in the api since your contract is quite new. The data in the api seems to have a couple days delay. They also seem to have some delays with contract updates as well at the moment.

Can you see any measurement data in their own app or Oma Helen web portal?

Anyway I should have implemented a check for this error – and probably will implement one for the next release!

lakofsth commented 1 year ago

Ok, thanks! There's data as of 16.1 for previous day in portal and app. I think your new contract delay explanation also makes sense based on some wording I saw in the portal.

Thanks for the integration, regardless.

carohauta commented 1 year ago

Now that I had more time to check the lines in the stacktrace it seems that the error occurs when calculating the costs of last month. So yeah, I definitely need to update the integration so that it does not crash all helen_energy components if some month does not have data.

Thanks for reaching out!

carohauta commented 1 year ago

This should be fixed now in the latest release 1.0.1

lakofsth commented 1 year ago

Thanks. I'll update now and see what happens tomorrow.

lakofsth commented 1 year ago

HACS found the update in your repository, and installed it. I see following in log still:

Logger: homeassistant.components.sensor Source: custom_components/helen_energy/sensor.py:111 Integration: Sensor (documentation, issues) First occurred: 23 January 2023 at 23:11:39 (1 occurrences) Last logged: 23 January 2023 at 23:11:39 helen_energy: Error on device update!

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 503, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 729, in async_device_update await task File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/helen_energy/sensor.py", line 335, in update _get_total_consumption_for_last_month(self._api_client) File "/config/custom_components/helen_energy/sensor.py", line 122, in _get_total_consumption_for_last_month return _get_total_consumption_between_dates(helen_api_client, start_date, end_date) File "/config/custom_components/helen_energy/sensor.py", line 111, in _get_total_consumption_between_dates measurement_response.intervals.electricity[0].measurements, IndexError: list index out of range

carohauta commented 1 year ago

Oh cool HACS detects the new tags and offers updates.

However I added a new fix and this time it should actually work.

The last update I did was only for the underlying oma-helen-cli library. Did not realize that the integration code had the same bug as well.

lakofsth commented 1 year ago

I'll check it as soon as HACS notices the update. Thanks!

On Tue, 24 Jan 2023 at 11:16, Caro Hautamäki @.***> wrote:

Oh cool HACS detects the new tags and offers updates.

However I added a new fix and this time it should actually work.

The last update I did was only for the underlying oma-helen-cli library. Did not realize that the integration code had the same bug as well.

— Reply to this email directly, view it on GitHub https://github.com/carohauta/oma-helen-ha-integration/issues/2#issuecomment-1401606256, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDHVSV7MHJQFT7KNUD5FYDWT6MYVANCNFSM6AAAAAAT5UOKLA . You are receiving this because you authored the thread.Message ID: @.***>

lakofsth commented 1 year ago

It works. Thanks for the prompt work on the fixes!

On Tue, 24 Jan 2023, 11.16 Caro Hautamäki, @.***> wrote:

Oh cool HACS detects the new tags and offers updates.

However I added a new fix and this time it should actually work.

The last update I did was only for the underlying oma-helen-cli library. Did not realize that the integration code had the same bug as well.

— Reply to this email directly, view it on GitHub https://github.com/carohauta/oma-helen-ha-integration/issues/2#issuecomment-1401606256, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDHVSV7MHJQFT7KNUD5FYDWT6MYVANCNFSM6AAAAAAT5UOKLA . You are receiving this because you authored the thread.Message ID: @.***>

carohauta commented 1 year ago

Fixed in 1f96fdd377f890e1cb4ed698fb5f06b93173b1d8