Skip to content

feat(decoders): ✨ add public decode_masked_flag helper - #66

Merged
svasek merged 1 commit into
mainfrom
feat/decode-masked-flag
Aug 27, 2026
Merged

feat(decoders): ✨ add public decode_masked_flag helper#66
svasek merged 1 commit into
mainfrom
feat/decode-masked-flag

Conversation

@svasek

@svasek svasek commented Aug 27, 2026

Copy link
Copy Markdown
Owner

🧩 What

Add a public decode_masked_flag(flag, data) helper to neopool_modbus.decoders.

It isolates a MaskedFlag's field from an async_read_all() snapshot via the library's own mask/shift layout, so callers do not have to maintain protocol masks themselves. Returns None when the shared register is absent.

💡 Why

async_set_masked_register already owns the write side of packed registers (for example HIDRO_COVER_REDUCTION_PERCENT and HIDRO_SHUTDOWN_TEMPERATURE, which share register 0x042D). 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: new decode_masked_flag(flag, data) reading _MASKED_FLAG_LAYOUT
  • 📦 export it in decoders.__all__
  • test_decoders.py: cover both fields from a packed 0x0C19 (25 / 12) and the None-when-absent path
  • 📝 README.md: list the helper in the public API and document it as the read counterpart to async_set_masked_register

✅ Verification

  • pytest full suite passes; decoders.py at 100% coverage
  • ruff check, ruff format --check, basedpyright clean on the touched files

- 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

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f879d54) to head (edfcb0d).
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@svasek svasek self-assigned this Aug 27, 2026
@svasek svasek added the enhancement New feature or request label Aug 27, 2026
@svasek
svasek merged commit b039b0a into main Aug 27, 2026
11 checks passed
@svasek
svasek deleted the feat/decode-masked-flag branch August 27, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant