hekmon / linkytic

Linky TIC support for Home Assistant
MIT License
49 stars 15 forks source link

Connection impossible via SerialServer #48

Open bagl3y opened 2 days ago

bagl3y commented 2 days ago

Bonjour,

J'utilise SerialServer pour me connecter à mon module TIC via le réseau.

Quand je tape mon url : rfc2217://192.168.42.239:2217 , j'ai une erreur : Erreur inattendue

Coté Logs HA, j'ai une error suivi d'une stacktrace :

2024-11-20 19:26:27.749 ERROR (MainThread) [custom_components.linkytic.config_flow] Unexpected exception: Caught blocking call to sleep with args (0.3,) inside the event loop by custom integration 'linkytic' at custom_components/linkytic/serial_reader.py, line 469: serial_reader = serial.serial_for_url(. (offender: /usr/local/lib/python3.12/site-packages/serial/rfc2217.py, line 557: time.sleep(0.3)), please create a bug report at https://github.com/hekmon/linkytic/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#sleep
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/serial/rfc2217.py", line 477, in open
    time.sleep(0.05)    # prevent 100% CPU load
    ^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 192, in protected_loop_func
    raise_for_blocking_call(
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 158, in raise_for_blocking_call
    raise RuntimeError(
RuntimeError: Caught blocking call to sleep with args (0.05,) inside the event loop by custom integration 'linkytic' at custom_components/linkytic/serial_reader.py, line 469: serial_reader = serial.serial_for_url(. (offender: /usr/local/lib/python3.12/site-packages/serial/rfc2217.py, line 477: time.sleep(0.05)    # prevent 100% CPU load), please create a bug report at https://github.com/hekmon/linkytic/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#sleep
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/config/custom_components/linkytic/config_flow.py", line 76, in async_step_user
    linky_tic_tester(
  File "/config/custom_components/linkytic/serial_reader.py", line 469, in linky_tic_tester
    serial_reader = serial.serial_for_url(
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/serial/__init__.py", line 90, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.12/site-packages/serial/rfc2217.py", line 496, in open
    self.close()
  File "/usr/local/lib/python3.12/site-packages/serial/rfc2217.py", line 557, in close
    time.sleep(0.3)
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 192, in protected_loop_func
    raise_for_blocking_call(
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 158, in raise_for_blocking_call
    raise RuntimeError(
RuntimeError: Caught blocking call to sleep with args (0.3,) inside the event loop by custom integration 'linkytic' at custom_components/linkytic/serial_reader.py, line 469: serial_reader = serial.serial_for_url(. (offender: /usr/local/lib/python3.12/site-packages/serial/rfc2217.py, line 557: time.sleep(0.3)), please create a bug report at https://github.com/hekmon/linkytic/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#sleep

Core: 2024.11.2 Supervisor: 2024.11.2 Operating System: 13.2 Interface utilisateur: 20241106.2

Essayé avec la version 2.0.7 et 3.0.0-beta4

tomleglaunec commented 1 day ago

Bonjour, il s'agit bien d'un bug de l'intégration, qui n'affecte à priori que l'utilisation via rfc2217

L'implémentation rfc2217 de pyserial utilise des appels bloquants à sleep, qui est empêché par HomeAssistant si appelé depuis la boucle d'évènement principale. L'intégration utilise un thread séparé mais l'initialisation de la communication au démarrage et le test de connexion lors de l'ajout d'un appareil ne s'exécute pas dans le contexte de ce thread.

Je travaille sur le correctif