carohauta / oma-helen-ha-integration

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

helen_energy: Error on device update! #20

Closed samroyt closed 5 months ago

samroyt commented 6 months ago

Integration was working ok for a while, but a few weeks ago I started to see this in the home assistant logs:

helen_energy: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 599, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1261, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/helen_energy/sensor.py", line 555, in update
    _get_total_consumption_for_current_month(self._api_client)
  File "/config/custom_components/helen_energy/sensor.py", line 215, in _get_total_consumption_for_current_month
    return _get_total_consumption_between_dates(helen_api_client, start_date, end_date)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/helen_energy/sensor.py", line 190, in _get_total_consumption_between_dates
    helen_api_client.get_daily_measurements_between_dates(start_date, end_date)
  File "/usr/local/lib/python3.12/site-packages/cachetools/__init__.py", line 641, in wrapper
    v = func(*args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/helenservice/api_client.py", line 157, in get_daily_measurements_between_dates
    response_json_text = get(
                         ^^^^
TypeError: get() takes 1 positional argument but 2 were given

I've updated to the latest version of this integration, updated home assistant, and tried reinstalling the integration but it does not help.

I'm using smart guarantee sensor template.

carohauta commented 6 months ago

Did it start happening after updating HA? Or something similar?

The error is a bit confusing. I know for a fact that requests.get function actually does take two positional arguments instead of one (ever since Requests 2.7).

Could there perhaps be some sort of mix up with dependencies, especially with the Requests library 🤷‍♂️ I am not able to reproduce this error in any environment.

samroyt commented 6 months ago

Unfortunately I'm not sure on the exact time this started happen, but I've done some HA updates.

Here's oma-helen-cli and Requests versions from pip freeze on the home assistant container if that helps:

oma-helen-cli==1.3.0

requests==2.31.0
requests-file==2.0.0
requests-futures==1.0.1
requests-oauthlib==1.3.1
requests-toolbelt==1.0.0
requests-unixsocket==0.3.0

Launching oma-helen-cli from the shell in container seems to work and I can get data. So I'm not sure is the integration using those versions or running in virtualenv.

carohauta commented 6 months ago

That confirms that the requests library version is correct.

The stack trace also has this section which points to cachetools:

  File "/usr/local/lib/python3.12/site-packages/cachetools/__init__.py", line 641, in wrapper
    v = func(*args, **kwargs)

The cachetools version which oma-helen-cli depends on is 5.2.0. That version does not officially support Python 3.12 so there could be something there.

I will update the dependencies and publish a new version when I get to it. Meanwhile, you may want to try it by yourself in your own instance. Just update cachetools to version 5.3.3 and see if it makes a difference.

samroyt commented 6 months ago

After updating cachetools to 5.3.3 it still fails the same way:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 599, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1261, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/helen_energy/sensor.py", line 555, in update
    _get_total_consumption_for_current_month(self._api_client)
  File "/config/custom_components/helen_energy/sensor.py", line 215, in _get_total_consumption_for_current_month
    return _get_total_consumption_between_dates(helen_api_client, start_date, end_date)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/helen_energy/sensor.py", line 190, in _get_total_consumption_between_dates
    helen_api_client.get_daily_measurements_between_dates(start_date, end_date)
  File "/usr/local/lib/python3.12/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/helenservice/api_client.py", line 157, in get_daily_measurements_between_dates
    response_json_text = get(
                         ^^^^
TypeError: get() takes 1 positional argument but 2 were given
samroyt commented 5 months ago

After updating to home assistant 2024.4.1 this started to work again.

It was still failing with the previous 2024.3.3 with same helen_energy 1.3.2 version.

Before the update I created completely new container with same 2024.3.3, same helen_energy 1.3.2 and configurations for it and that was also working fine.

I have some backups still from the failing setup if you want me to debug this more, but I'm happy now that this works again :)

carohauta commented 5 months ago

Nice to hear that it's working again!

No need to debug this further. Open a new issue if more problems arise.