Lift a shared known() lookup for the IntEnum fallback pattern #99
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/enum-lookup-helper"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Five places each did the same try/except of looking a raw int up in an
IntEnum, falling back when unknown:
word_forin alarms.py,mode_of,kind_of,semantic_of,node_name, and_result_namein the updater.Adds
protocol/enums.pywithknown(enum, raw) -> E | None(stdlib only,since the updater mounts
protocol/alone), plusword()for thename-or-raw-int case
word_forcovered. Each of the five now expressesitself as a one-liner over
known.word_formoves out of alarms.py sinceit was never alarm-specific; its four importers (alarms, lockout, select,
binary_sensor) now pull
wordfromprotocol.enumsinstead.No behaviour change — existing tests are the gate, all green under
tools/check.Reviewed (note: PR was already merged by the time this review ran).
Checked all five call sites against their original try/except behaviour —
known()is used with an explicitis None/is not Nonecheck everywhere, so there's no falsy-zero trap even though several enum members (e.g.AlarmState.CLEARED = 0,PresentationKind/SemanticClassmembers at 0) sit at value 0.word()inprotocol/enums.pyreproducesword_forexactly (name-or-raw fallback), and all four importers (alarms.py, lockout.py, select.py, binary_sensor.py) were updated — no leftoverword_forreferences anywhere (grepped the whole tree).mode_of,kind_of,semantic_of,node_name,_result_nameare each faithful one/two-liners overknown(), preserving their original fallback value and public signature.protocol/enums.pyimports onlyenum.IntEnum— stdlib-only, safe for the updater's standalone mount ofprotocol/.IntEnumimport stays inalarms.py(still used byAlarmState/Severity), so nothing unused there.coordinator.pyor any entity/platform pass-through methods, so no overlap with concurrent work there.def known[E: IntEnum]) is fine sincepyproject.tomltargetspy314.Couldn't get a clean
./tools/checkrun to completion — the review worktree was removed mid-run (looks like it was cleaned up once the PR merged). The partial run before that showed lint/format/types green, but a batch of test failures/errors spread across files this PR doesn't touch at all (test_manifest, test_release, test_stamp_build, test_firmware_updates, etc.), which points to a pre-existing environment issue rather than something this change caused. Worth a clean run in CI to confirm, but nothing in the diff itself looks like the cause.No blocking findings.