RainerStaude / hass-becker-component-plus-pybecker

A native home assistant component to control becker RF shutters with a Becker Centronic USB Stick.
MIT License
46 stars 4 forks source link

Serial connection over TCP not working? #46

Open Flink opened 1 week ago

Flink commented 1 week ago

Not wanting to hijack an existing issue (like https://github.com/RainerStaude/hass-becker-component-plus-pybecker/issues/39), so opening a new one :sweat_smile:

I tried to setup my becker USB dongle with a small serial over TCP server to be able to use is from anywhere on the network. It actually works, if I use the pybecker lib directly on the command line, I can move my blinds. But when I try to use the HA integration, it doesn’t work. On the server side, I can see there’s a connection stuck in ESTABLISHED mode. And no commands get through. HA also complains with this in the logs:

Detected blocking call to import_module with args ('serial.urlhandler',) inside the event loop by custom integration 'becker' at custom_components/becker/pybecker/becker_helper.py, line 101: self._connection = serial.serial_for_url( (offender: /usr/local/lib/python3.12/site-packages/serial/init.py, line 74: importlib.import_module(package_name)), please report it to the author of the 'becker' custom integration For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/usr/src/homeassistant/homeassistant/setup.py", line 416, in _async_setup_component result = await task File "/usr/src/homeassistant/homeassistant/components/cover/init.py", line 158, in async_setup await component.async_setup(config) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 147, in async_setup self.hass.async_create_task_internal( File "/usr/src/homeassistant/homeassistant/core.py", line 829, in async_create_task_internal task = create_eagertask(target, name=name, loop=self.loop) File "/usr/src/homeassistant/homeassistant/util/async.py", line 45, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 308, in async_setup_platform await self._platforms[key].async_setup(platform_config, discovery_info) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 298, in async_setup await self._async_setup_platform(async_create_setup_awaitable) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_setup_platform awaitable = create_eagertask(awaitable, loop=hass.loop) File "/usr/src/homeassistant/homeassistant/util/async.py", line 45, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/config/custom_components/becker/cover.py", line 100, in async_setup_platform PyBecker.setup(hass, device=device, filename=filename) File "/config/custom_components/becker/rf_device.py", line 58, in setup cls.becker = Becker(device_name=device, init_dummy=False, db_filename=filename, callback=callback) File "/config/custom_components/becker/pybecker/becker.py", line 58, in init self.communicator = BeckerCommunicator(device_name, callback) File "/config/custom_components/becker/pybecker/becker_helper.py", line 217, in init self._connection = BeckerConnection(device=device) File "/config/custom_components/becker/pybecker/becker_helper.py", line 101, in init self._connection = serial.serial_for_url(

It seems the integration tries to open a blocking connection to the serial server instead of connecting only when sending a command, or something similar?

RainerStaude commented 4 days ago

Let me check that. To be honest I have never checked the connection over IP, but tried to keep it in the integration. Looks like you're probably the first one using this. Is there a good guide available how to setup such a TCP Server? Just a simple loopback would be perfect to test this. And of course I need some time on a rainy weekend 😉