Skip to content

fix(ble): harden poll-period options flow (code-review follow-ups) - #49

Merged
aaearon merged 2 commits into
mainfrom
fix/ble-poll-period-review-followups
Jun 15, 2026
Merged

fix(ble): harden poll-period options flow (code-review follow-ups)#49
aaearon merged 2 commits into
mainfrom
fix/ble-poll-period-review-followups

Conversation

@aaearon

@aaearon aaearon commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Targeted fixes from a code review of the configurable BLE poll-period feature (#42). The per-charger walkthrough UX is unchanged.

Fixes

  1. Clamp stored poll period on read (__init__.py, const.py) — new valid_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).
  2. Prune orphan period keys (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.
  3. Don't reject a disable submission on a blank period (config_flow.py) — period field is now vol.Optional (keeps its default), so a disable-only submission falls back to the default instead of raising InvalidData. Out-of-range values are still rejected.
  4. Remove redundant _original_periods field (config_flow.py) — form default now computed from self._periods, which already carries the saved values for unvisited serials.
  5. Use HA selectors (config_flow.py) — NumberSelector/BooleanSelector replace raw vol.All/Coerce/Range, making const.py the single source of the bounds. The existing float(...) guard is retained.
  6. Remove dead init options-step strings (strings.json, translations/en.json) — async_step_init always redirects to charger, so the init step block was unused. Also dropped the duplicated "1–60" range from the field label (kept "(seconds)").
  7. Multi-charger walkthrough test (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 existing test_options_flow_preserves_period_on_disable and test_options_flow_rejects_out_of_range_period remain green.

aaearon added 2 commits June 15, 2026 17:25
- 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
@aaearon
aaearon merged commit 322cb8a into main Jun 15, 2026
5 checks passed
@aaearon
aaearon deleted the fix/ble-poll-period-review-followups branch June 15, 2026 15:31
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