veista / nilan

Nilan integration for Home Assistant
Apache License 2.0
45 stars 10 forks source link

Workaround 2024.4 setup issue #124

Closed kfroeschl closed 3 months ago

kfroeschl commented 3 months ago

After HA 2024.4 the Modbus async_setup call does not longer wait for the modbus connection.

Thus you will receive the errors:

2024-04-04 11:56:17.249 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: Nilan: Error: device: 30 address: 1000 -> Modbus Error: [Connection] Not connected[AsyncModbusSerialClient /dev/ttyUSB2:0]
2024-04-04 11:56:17.280 ERROR (MainThread) [custom_components.nilan.device] Could not read get_machine_type
2024-04-04 11:56:17.280 DEBUG (MainThread) [custom_components.nilan.device] Device Type = None
2024-04-04 11:56:17.283 WARNING (MainThread) [homeassistant.components.modbus.modbus] modbus Nilan communication closed

As well as the follwing errors because the connection is not closed properly:

2024-04-03 23:10:30.901 WARNING (MainThread) [py.warnings] /config/custom_components/nilan/device.py:65: RuntimeWarning: coroutine 'ModbusHub.async_close' was never awaited
  self._modbus.async_close()

2024-04-03 23:32:56.379 WARNING (MainThread) [pymodbus.logging] Failed to connect [Errno 11] Could not exclusively lock port /dev/ttyUSB2: [Errno 11] Resource temporarily unavailable
2024-04-03 23:34:16.553 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: Nilan: Error: device: 30 address: 1000 -> Modbus Error: [Connection] Not connected[AsyncModbusSerialClient /dev/ttyUSB2:0]

This may have been caused by recent HA modbus changes to switch to async Clients: https://github.com/home-assistant/core/commit/7cba34b2e6b53621e6188ff2b473a3553e72bdcd?diff=split&w=0

Note:

jseedorff commented 3 months ago

Just added your workaround manually. It works well for me. Thanks.

maeklund86 commented 3 months ago

Updated directly to 2024.4.1 after making the modifications manually, and worked like a charm. Thanks @kfroeschl!

veista commented 3 months ago

Thank you so much for helping out with this issue! I decided to implement a different solution, but your help is really appreciated!