Add configurable handshake timeout#2064
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2064 +/- ##
==========================================
+ Coverage 83.49% 83.64% +0.14%
==========================================
Files 199 199
Lines 19522 19537 +15
Branches 1058 1063 +5
==========================================
+ Hits 16300 16341 +41
+ Misses 3036 3006 -30
- Partials 186 190 +4 ☔ View full report in Codecov by Harness. |
Contributor
Author
|
These changes were generated using Claude Code under my supervision. I reviewed and approved all code before submitting. I'm not very familiar with this codebase, so apologies in advance for any mistakes. |
d2b2f65 to
49ab961
Compare
rytilahti
reviewed
Jun 27, 2026
Comment on lines
+120
to
+122
| The decision is based on _handshake_timeout, which is set in __init__ | ||
| either from the explicit handshake_timeout parameter, or derived from | ||
| the legacy lazy_discover flag: |
Owner
There was a problem hiding this comment.
It is enough to describe the logic briefly, no need to name the exact variable names etc. in this docstring.
Maybe the main docstring for the class could describe why you want to use these variables (lazy_discover was never really properly documented), but it is also good as it is.
Some devices need a recent handshake to respond, but the current lazy_discover flag only offers two extremes: handshake once (True) or before every request (False). This adds a handshake_timeout parameter (in seconds) that re-handshakes only when enough time has passed since the last one. The lazy_discover flag is preserved for backward compatibility and translated into the new timeout internally. Addresses rytilahti#1683
Covers the two lines flagged by Codecov: the _last_handshake assignment in send_handshake() and the _needs_handshake() call in send().
06e59df to
2a88a64
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current
lazy_discoverflag only offers two extremes: handshake once on first request (True), or before every request (False). Devices that need a recent handshake but not on every request (referenced in HA issues #59215, #92774) have no middle ground.This adds a
handshake_timeoutparameter (in seconds) toMiIOProtocolandDevice. It tracks when the last handshake occurred and only re-handshakes when enough time has passed. Setting it to0matcheslazy_discover=False, and leaving it unset preserves existing behavior.The
lazy_discoverparameter is kept for backward compatibility - it's translated into the timeout internally.Changes:
miioprotocol.py:_needs_handshake()replaces the inline boolean check,_last_handshaketimestamp recorded on each handshakedevice.py: threadshandshake_timeoutkwarg through toMiIOProtocolFull test suite: 1294 passed (same as master), no new failures. Ruff clean.
Addresses #1683
Fixes #1683