Skip to content

Migrate codes to Flipper .sub format with lazy loader#2

Merged
balloob merged 2 commits into
mainfrom
feat/flipper-sub-format
Apr 18, 2026
Merged

Migrate codes to Flipper .sub format with lazy loader#2
balloob merged 2 commits into
mainfrom
feat/flipper-sub-format

Conversation

@balloob
Copy link
Copy Markdown
Contributor

@balloob balloob commented Apr 18, 2026

Summary

  • Adopt Flipper Zero .sub as the code storage format. Codes live under rf_protocols/codes/<vendor>/<device>/<command>.sub in 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.
  • Lazy loader. New load_codes(path, base_dir=None) returns a CodeCollection. It resolves the device directory (and rejects path traversal) but does not read any .sub file. 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.
  • Simplify timings. OOKCommand.timings is now list[int] using Flipper's signed-alternating convention (positive pulse µs, negative space µs) instead of a Timing dataclass. The .sub values are stored verbatim — no conversion layer — and the Timing class is dropped entirely.

Usage:

from rf_protocols import load_codes

codes = load_codes("honeywell/string_lights")  # resolves dir, no file reads
cmd = codes.load_command("TURN_ON")            # reads + parses one .sub file

Test plan

  • pytest — 21 tests pass, including a parametrized test that walks every bundled .sub file and asserts it parses into a valid OOK command
  • ruff check / ruff format / basedpyright clean via prek --all-files
  • Wire up in a downstream HA integration to confirm the load_codes / load_command split feels right in practice

🤖 Generated with Claude Code

balloob and others added 2 commits April 17, 2026 23:18
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant