Migrate codes to Flipper .sub format with lazy loader#2
Merged
Conversation
Store RF command codes as Flipper Zero `.sub` files (one per button) under `rf_protocols/codes/<vendor>/<device>/` so captures taken from a real Flipper drop in as-is, and our codes can be shared back. Add `load_codes(path, base_dir=None)` returning a `CodeCollection`. Construction resolves the device directory; files are only read and parsed when `load_command(name)` is called, with results cached per instance. This keeps HA startup cheap and defers I/O until needed. Simplify `OOKCommand.timings` from `list[Timing]` to `list[int]` using Flipper's signed-alternating convention (positive pulse µs, negative space µs) so loaded values are stored verbatim. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
.subas the code storage format. Codes live underrf_protocols/codes/<vendor>/<device>/<command>.subin Flipper's standard RAW SubGhz format. Captures taken on an actual Flipper drop in as-is, and anything we add here can be used directly by Flipper users — promotes reuse of existing work in both directions. Honeywell string lights is migrated as the first example.load_codes(path, base_dir=None)returns aCodeCollection. It resolves the device directory (and rejects path traversal) but does not read any.subfile.CodeCollection.load_command(name)is where the file read + parse happens, cached per instance so repeat calls don't re-read. This keeps HA startup cheap and defers work until a command is actually sent.OOKCommand.timingsis nowlist[int]using Flipper's signed-alternating convention (positive pulse µs, negative space µs) instead of aTimingdataclass. The.subvalues are stored verbatim — no conversion layer — and theTimingclass is dropped entirely.Usage:
Test plan
pytest— 21 tests pass, including a parametrized test that walks every bundled.subfile and asserts it parses into a valid OOK commandruff check/ruff format/basedpyrightclean viaprek --all-filesload_codes/load_commandsplit feels right in practice🤖 Generated with Claude Code