fix(mqtt): support both 'st/did' and 'status/feature' keys#83
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the MQTT subscriptions message parsing to accept multiple key variants used by different Navien device protocol versions, so DeviceStatus / DeviceFeature parsing continues to work across hardware/firmware variants.
Changes:
- Added alternate key support when extracting parsed payloads from MQTT response messages (e.g.,
statusvsst,featurevsdid).
…cedence - Add get_response_data() helper to mqtt/utils.py that checks nested response dict before top-level, and primary key before alt key: res[key] → res[alt_key] → message[key] → message[alt_key] - Use helper in _make_handler() fixing the fallback order (previously message[key] was checked before res[alt_key]) - Use same helper in CLI raw_cb path so 'st'/'did' alt keys are supported there too, consistent with the typed handler path - Fix missing return None in EnergyUsageResponse.get_month_data - Fix mypy no-any-return in MqttConnection.unsubscribe/publish
Replace or-chain with explicit key-presence checks using a sentinel
object, so falsy values (0, False, {}) are returned correctly and do
not fall through to a lower-precedence candidate.
Also add unit tests for the raw=True CLI path with 'st'/'did' alt keys
and the standard 'status'/'feature' keys.
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.
Some Navien devices respond with 'st' and 'did' keys instead of the full 'status' and 'feature' names used in the library's Pydantic models. This PR adds support for both to ensure compatibility with all hardware versions.