Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After reading your comment, I've analyzed the source code and found out, that:
transport_write()
without a delay is called only fromexchange()
.exchange()
without a delay is called only fromstatus()
, always.status()
is called only in two places:hass-localtuya/custom_components/localtuya/coordinator.py
Line 231 in a34e316
hass-localtuya/custom_components/localtuya/core/pytuya/__init__.py
Line 1207 in a34e316
I can understand a need for sending requests without a delay only in the case of subsequent requests with no delay between them. So, I'm confident that the first call can be performed with the delay. Moreover, it is exactly the call that caused me problems.
I don't quite understand if the second call to
status()
(several calls in the loop, actually) may need to have no delays in between. I doubt it. But I'm confident that the first write can be done without a delay. So, I introduceddelay
parameter tostatus()
, and now it can beFalse
only being called fromdetect_available_dps()
. But I'd prefer to deletecommand_delay
parameter fromtransport_write()
as not actually used and as dangerous.Forgetting about
detect_available_dps()
, now I'm confident that the heartbeat does not require additional synchronization before sending requests. But I delayed the first heartbeat to let LocalTuya start faster and smoother.The 3rd commit (d1b07db) reverted traces of my experiment to ensure that
status()
is called only in two places: I've removed default parameters values to let python compiler to catch other calls, if any.In brief:
detect_available_dps()
is called periodically.command_delay
parameter fromtransport_write()
and then revert my second commit.