Concurrency on custom integration when both BinarySensor and Sensor are present

Team
I have this weird issue on concurrency.
I’ve developed a component to send and receive the status of the videoprojector, here is the code: msavazzi/homeassistant-jvc-dila (github.com)

Based on the Home Assistant TCP component it does have both a binary sensor as well as a sensor.

If I configure only one of the two it works perfectly, no errors.
if I configure both of them:

2022-12-29 18:24:57.235 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 1 - PJ_OK
2022-12-29 18:24:58.440 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 2 - PJACK
2022-12-29 18:24:59.074 ERROR (SyncWorker_4) [custom_components.jvc_dila.common] 1 Unable to connect to 192.168.1.94 on port 20554: [Errno 111] Connection refused
2022-12-29 18:24:59.642 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 3 - (6) b'\x06\x89\x01PW\n'
2022-12-29 18:25:00.244 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 4 - b'@\x89\x01PW0\n'
2022-12-29 18:25:00.276 WARNING (SyncWorker_4) [custom_components.jvc_dila.common] 1 -
2022-12-29 18:25:00.277 WARNING (SyncWorker_4) [custom_components.jvc_dila.common] Unable to send PJREQ on port 192.168.1.94: 20554 error [Errno 32] Broken pipe

and either of the items gives an error (usually the BinarySensor).

The correct flow should be (as is scheduled to run every 10 sec):

2022-12-29 18:33:45.902 WARNING (SyncWorker_6) [custom_components.jvc_dila.common] 1 - PJ_OK
2022-12-29 18:33:47.105 WARNING (SyncWorker_6) [custom_components.jvc_dila.common] 2 - PJACK
2022-12-29 18:33:48.316 WARNING (SyncWorker_6) [custom_components.jvc_dila.common] 3 - (6) b'\x06\x89\x01PW\n'
2022-12-29 18:33:48.917 WARNING (SyncWorker_6) [custom_components.jvc_dila.common] 4 - b'@\x89\x01PW1\n'
2022-12-29 18:33:55.904 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 1 - PJ_OK
2022-12-29 18:33:57.106 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 2 - PJACK
2022-12-29 18:33:58.308 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 3 - (6) b'\x06\x89\x01PW\n'
2022-12-29 18:33:58.909 WARNING (SyncWorker_7) [custom_components.jvc_dila.common] 4 - b'@\x89\x01PW1\n'

it appears it does try to open two connections to the projector at the same time

here is the config.yaml:

sensor:
  - platform: jvc_dila
    host: 192.168.1.94
    port: 20554
    scan_interval: 10

binary_sensor:
  - platform: jvc_dila
    host: 192.168.1.94
    port: 20554
    scan_interval: 10

Any suggestion?
any way to define it “single”? or avoid concurrency? also why is being invoked twice when I configure both BinarySensor and Sensor?

You should have a central coordinator inside your integration keyed by ip and port, so each new sensor using same ip and port, should use same coordinator.

All tcp communication should go over same coordinator and you can also use lock mechanism to be sure that this function is not run in parallel.