kodebach / hacs-idm-heatpump

HACS integration for IDM heat pumps
MIT License
24 stars 1 forks source link

Not working anymore with newer pymodbus, please upgrade to 3.6.6 (the version HA is using) #100

Closed onkelbeh closed 2 weeks ago

onkelbeh commented 6 months ago

First a big thanks for this component.

## Version of the custom_component 0.8.0, not using hacs, I have installed the current master branch at commit 513f66264fb7b6c49a6e283bc2c579977d9340f7 ## Configuration ```yaml no yaml config used, one pump configured per config flow Navigator 2.0, SW: 20.23-58 ``` ## Describe the bug Home Assistant currently pins pymodbus==3.6.6 https://github.com/home-assistant/core/blob/2024.3.3/homeassistant/components/modbus/manifest.json You have pymodbus==3.6.4 in https://github.com/kodebach/hacs-idm-heatpump/blob/v0.8.0/requirements.txt but still pymodbus==3.5.0 in https://github.com/kodebach/hacs-idm-heatpump/blob/v0.8.0/custom_components/idm_heatpump/manifest.json so actually idm-heatpump tries to load 3.5.0 After adjusting the version in manifest.json, it loads 3.6.6, and pulls all values from the pump exactly one time, but then all entities from the pump are not updated anymore, they stay at the values from the first run. ## Debug log
2024-03-23 08:24:10.824 ERROR (SyncWorker_0) [homeassistant.util.package] Unable to install package pymodbus==3.5.0

after adjusting the version in manifest.json, it loads, and pulls all values from the pump exactly one time, but then:

2024-03-23 08:25:45.025 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorSocketTransport._call_connection_lost(None)
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.12/asyncio/selector_events.py", line 1191, in _call_connection_lost
    super()._call_connection_lost(exc)
  File "/usr/lib/python3.12/asyncio/selector_events.py", line 911, in _call_connection_lost
    self._protocol.connection_lost(exc)
  File "/usr/lib/python3.12/site-packages/pymodbus/transport/transport.py", line 288, in connection_lost
    self.close(intern=True)
TypeError: AsyncModbusTcpClient.close() got an unexpected keyword argument 'intern'

Since 0.8.0, it loads all data from the heatpump after a restart. But then, after a couple of minutes (perhaps this is the next pull):

2024-03-23 08:31:25.557 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.557 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.557 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.557 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.557 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.

(several lines more here....)

2024-03-23 08:31:25.559 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:25.560 WARNING (MainThread) [asyncio] socket.send() raised exception.
2024-03-23 08:31:28.561 DEBUG (MainThread) [custom_components.idm_heatpump] got groups
2024-03-23 08:31:28.561 ERROR (MainThread) [custom_components.idm_heatpump] Unexpected error fetching idm_heatpump data: AsyncModbusTcpClient.close() got an unexpected keyword argument 'intern'
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 318, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/homeassistant/custom_components/idm_heatpump/coordinator.py", line 49, in _async_update_data
    raise exception
  File "/etc/homeassistant/custom_components/idm_heatpump/coordinator.py", line 41, in _async_update_data
    has_error, data = await self.heatpump.async_get_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/homeassistant/custom_components/idm_heatpump/idm_heatpump.py", line 303, in async_get_data
    raise next(e for e in groups if isinstance(e, Exception)) or Exception(
  File "/etc/homeassistant/custom_components/idm_heatpump/idm_heatpump.py", line 147, in _fetch_sensors
    result = await self._fetch_retry(group)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/homeassistant/custom_components/idm_heatpump/idm_heatpump.py", line 133, in _fetch_retry
    return await self._fetch_registers(group)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/etc/homeassistant/custom_components/idm_heatpump/idm_heatpump.py", line 125, in _fetch_registers
    return await self.client.read_input_registers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pymodbus/client/base.py", line 179, in async_execute
    self.close(reconnect=True)
  File "/usr/lib/python3.12/site-packages/pymodbus/client/tcp.py", line 92, in close
    super().close(reconnect=reconnect)
  File "/usr/lib/python3.12/site-packages/pymodbus/client/base.py", line 130, in close
    self.connection_lost(asyncio.TimeoutError("Server not responding"))
  File "/usr/lib/python3.12/site-packages/pymodbus/transport/transport.py", line 288, in connection_lost
    self.close(intern=True)
TypeError: AsyncModbusTcpClient.close() got an unexpected keyword argument 'intern'
2024-03-23 08:31:28.574 DEBUG (MainThread) [custom_components.idm_heatpump] Finished fetching idm_heatpump data in 12.033 seconds (success: False)

All entities from the pump are not updated anymore, they stay at the initially loaded values.

And at this opportunity another question: Is there a reason that version is always "0.0.0" in manifest.json?

onkelbeh commented 6 months ago

Imho, this looks related to https://github.com/pymodbus-dev/pymodbus/pull/2098/files. Looks like this is fixed in 3.6.6

onkelbeh commented 6 months ago

confirm, after upgrading to pymodbus 3.6.6 everything works again (Homeassistant-2024.3.3).

kodebach commented 6 months ago

Thanks for the detailed bug report and thorough investigation. I couldn't reproduce the issue yet, but I merged #95, which hopefully fixes this. Please confirm the issue is fixed on master, so I can publish a new release.

I have installed the current master branch

While the master branch should work, I generally wouldn't recommend that. If you don't want to use HACS, I would still recommend you stick to the tagged versions.

Is there a reason that version is always "0.0.0" in manifest.json?

AFAIK the field is more or less unused by Home Assistant itself (there seems to be some code related to blocking integrations that entirely break Home Assistant, but nothing else). So for development and testing using 0.0.0 works fine. And constantly updating the version would create useless noise in the git history.

For releases, there is a GitHub Actions workflow that sets the version field based on the release tag for use in HACS.

If you want to have the proper version in the manifest.json, you can download the idm_heatpump.zip file from the GitHub Releases like HACS does. The direct link should always be https://github.com/kodebach/hacs-idm-heatpump/releases/download/[version]/idm_heatpump.zip where [version] is e.g. v0.8.0.

onkelbeh commented 6 months ago

Yep, thanks. I do not use the (changed by https://github.com/kodebach/hacs-idm-heatpump/pull/95) requirements.txt. I copied the current master https://github.com/kodebach/hacs-idm-heatpump/commit/ffa981860cc5c7bedba552b5cecdc6a43071b36b again, still everything works on Home Assistant 2024.3.3, with pymodbus-3.6.6, currently I am only reading from the pump.

Updating manifest.json with the current release and requirements is a good idea, hard pinning the requirement certainly not, I'd suggest you put a minimum version like 'pymodbus>=3.6.6' in your manifest. In one of my other lifes, I am maintaining https://github.com/onkelbeh/HomeAssistantRepository, an Overlay to run Home Assistant on Gentoo Linux, and I had this discussion many times.

In a nutshell, the only place where requirements should be pinned (for some reason) is Home Assistant Core. https://github.com/home-assistant/core/blob/dev/requirements_all.txt is generated on every release, collecting all requirements from various places. All other dependants should not pin (unneccesary) version numbers for dependencies.

jurica commented 6 months ago

I can also confirm, that pymodbus 3.6.6 fixes the issue. Had the same issue after upgrading to homeassistant 2024.3.1 a few days ago, so I downgraded to 2024.5 again. Today I updated homeassistant to 2024.3.3 and IDM heat pump is still working. I have v0.8.0 installed via HACS

AndyNew2 commented 4 months ago

This pymodbus library is a pain. It destroyed my modbus integration by nearly all latest updates due to "some" changes. Of course everything I have is against the spec, however was working before. Hope I can upgrade to latest HA, stopped in April due to a lot of issues.

AndyNew2 commented 3 weeks ago

Hi, I updated to beta6 but have issues:

2024-09-07 19:44:30.348 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] IDM_Waermepumpe_PV_schreiben: Error executing script. Error for call_service at pos 2: Must acknowledge risk to call set_power 2024-09-07 19:44:30.349 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] Error while executing automation automation.idm_waermepumpe_pv_schreiben: Must acknowledge risk to call set_power 2024-09-07 19:45:00.324 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] IDM_Waermepumpe_PV_schreiben: Error executing script. Error for call_service at pos 2: Must acknowledge risk to call set_power 2024-09-07 19:45:00.324 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] Error while executing automation automation.idm_waermepumpe_pv_schreiben: Must acknowledge risk to call set_power 2024-09-07 19:45:30.324 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] IDM_Waermepumpe_PV_schreiben: Error executing script. Error for call_service at pos 2: Must acknowledge risk to call set_power 2024-09-07 19:45:30.325 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] Error while executing automation automation.idm_waermepumpe_pv_schreiben: Must acknowledge risk to call set_power 2024-09-07 19:46:00.323 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] IDM_Waermepumpe_PV_schreiben: Error executing script. Error for call_service at pos 2: Must acknowledge risk to call set_power 2024-09-07 19:46:00.324 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] Error while executing automation automation.idm_waermepumpe_pv_schreiben: Must acknowledge risk to call set_power

I am on HA 2024.7.4 do you think it is related to that? I updated HACS to 2.0.1

AndyNew2 commented 2 weeks ago

I updated now HA to 2024.9.1 and also HA OS to newest version. No change still got this log: 2024-09-08 10:37:30.055 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] IDM_Waermepumpe_PV_schreiben: Error executing script. Error for call_service at pos 2: Must acknowledge risk to call set_power 2024-09-08 10:37:30.056 ERROR (MainThread) [homeassistant.components.automation.idm_waermepumpe_pv_schreiben] Error while executing automation automation.idm_waermepumpe_pv_schreiben: Must acknowledge risk to call set_power

kodebach commented 2 weeks ago

Hi, I updated to beta6 but have issues:

Nothing to do with this issue, therefore hidden as off topic. Please see https://github.com/kodebach/hacs-idm-heatpump/issues/123#issuecomment-2336642522 for more.