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.
This PR reworks socket receiving (again). It separates read retries from send retries and tries a bit harder to receive a valid message.
If a null payload is received, it treats it as an ACK and will not resend a command even if no actual payload is ever received.
If a null payload or corrupt message is received, it retries the read (but not the send).
If a generic exception or socket timeout is encountered without first receiving a null payload, it retries the send. (This matches the existing behavior, it is not a change.)
If a generic exception is encountered after receiving a null payload, it retries the read (but not the send).
If a socket timeout is encountered after receiving a null payload, it immediately returns None.
Decryption failures now return a json error instead of None as that seems to be the more correct thing to do. If it is a null payload then decryption is skipped and None is returned.
In addition, it now searches the received data for the message start prefix. This could help with temperamental bulbs/devices if they send an extra NUL or other garbage before the start prefix or if a message somehow "tears" into 2 packets with the 2nd half badly delayed.