fix(ble): harden poll-period options flow (code-review follow-ups) - #49
Merged
Conversation
- Clamp/validate stored BLE poll period on setup (valid_poll_period helper) - Prune orphan poll-period keys for externally-removed serials on finalize - Make the poll-period field optional so disable-only submissions don't fail - Switch the options field to HA Number/Boolean selectors (const.py is the single source of the 1-60 s bounds) - Remove the redundant _original_periods flow field - Remove the dead 'init' options-step strings (always redirects to charger) - Add multi-charger walkthrough + validation test coverage
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.
Targeted fixes from a code review of the configurable BLE poll-period feature (#42). The per-charger walkthrough UX is unchanged.
Fixes
__init__.py,const.py) — newvalid_poll_period()helper returns a finite float within [1, 60] s, else the 3 s default. A corrupt/hand-edited stored value (None, non-numeric, 0, negative, out-of-range) no longer flows into the poller (was a busy-loop / TypeError risk).config_flow.py) — on finalize, persist only periods whose serial was walked this session (s in self._all_serials), dropping stale keys for serials removed externally.config_flow.py) — period field is nowvol.Optional(keeps its default), so a disable-only submission falls back to the default instead of raisingInvalidData. Out-of-range values are still rejected._original_periodsfield (config_flow.py) — form default now computed fromself._periods, which already carries the saved values for unvisited serials.config_flow.py) —NumberSelector/BooleanSelectorreplace rawvol.All/Coerce/Range, makingconst.pythe single source of the bounds. The existingfloat(...)guard is retained.initoptions-step strings (strings.json,translations/en.json) —async_step_initalways redirects tocharger, so theinitstep block was unused. Also dropped the duplicated "1–60" range from the field label (kept "(seconds)").tests/test_ble_config_flow.py) — drives two serials (disable first, keep second with custom period) and asserts the form sequence + accumulation.Tests
326 passed(full suite, Python 3.12). New tests cover the corrupt/valid stored-period cases, orphan pruning, blank-period disable, and the multi-charger walkthrough. The existingtest_options_flow_preserves_period_on_disableandtest_options_flow_rejects_out_of_range_periodremain green.