Hello!
I’m working on a custom component for a new integration which communicates to a gateway of a smart home system via TCP socket. I’m almost done with it, but when I started wider testing I discovered a major problem. When I execute a scene or control a group of entities (e.g. with a light group switch in GUI) HA sends the control commands so fast, that the gateway I sent my TCP queries to is not able to process them all and looses some of them. As a result some lights are not switched on/off.
Question: how to solve such an issue?? In HA everything is async and happens in parallel. In my log I see that the control commands are sent from HA using 3 different ‘threads’ (sync workers):
See below:
2019-11-11 16:18:29 DEBUG (SyncWorker_9) [custom_components.extalife.pyextalife] TCP command to execute: b'{"command": 20, "data": {"id": 0, "channel": 1, "state": 1, "value": 32}}\x03'
2019-11-11 16:18:29 DEBUG (SyncWorker_4) [custom_components.extalife.pyextalife] TCP command to execute: b'{"command": 20, "data": {"id": 5, "channel": 1, "state": 1, "value": 0}}\x03'
2019-11-11 16:18:29 DEBUG (SyncWorker_2) [custom_components.extalife.pyextalife] TCP command to execute: b'{"command": 20, "data": {"id": 14, "channel": 1, "state": 1, "value": 27}}\x03'
I guess I either need to enqueue these calls somehow and execute them sequentially or have some bigger delay between them to allow the gateway to process them and be ready to receive the next ones.
Right now I have no clue how to solve this. Any suggestions from your side guys?
PS. My component is synchronous as I’m too new to Python and asyncio and HA to be able to make it async.