feat(decoders): ✨ add public decode_masked_flag helper - #66
Merged
Conversation
- decode a value packed into a shared register from a coordinator-data snapshot - isolate a MaskedFlag's field via the library mask/shift layout so callers do not maintain protocol masks - return None when the shared register is absent - document the helper in the README public API as the read counterpart to async_set_masked_register
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 1223 1230 +7
=========================================
+ Hits 1223 1230 +7 ☔ View full report in Codecov by Harness. |
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.
🧩 What
Add a public
decode_masked_flag(flag, data)helper toneopool_modbus.decoders.It isolates a
MaskedFlag's field from anasync_read_all()snapshot via the library's own mask/shift layout, so callers do not have to maintain protocol masks themselves. ReturnsNonewhen the shared register is absent.💡 Why
async_set_masked_registeralready owns the write side of packed registers (for exampleHIDRO_COVER_REDUCTION_PERCENTandHIDRO_SHUTDOWN_TEMPERATURE, which share register0x042D). There was no matching read helper, so consumers had to duplicate the same masks and shifts to decode those fields. This adds the read counterpart and keeps the mask layout a single library concern.🔧 Changes
decoders.py: newdecode_masked_flag(flag, data)reading_MASKED_FLAG_LAYOUTdecoders.__all__test_decoders.py: cover both fields from a packed0x0C19(25 / 12) and theNone-when-absent pathREADME.md: list the helper in the public API and document it as the read counterpart toasync_set_masked_register✅ Verification
pytestfull suite passes;decoders.pyat 100% coverageruff check,ruff format --check,basedpyrightclean on the touched files