Skip to content

Add number entity for the pool chlorine setpoint - #4

Open
werdnum wants to merge 2 commits into
robmarkoski:mainfrom
werdnum:feature/pool-chlorine-setpoint
Open

werdnum wants to merge 2 commits into
robmarkoski:mainfrom
werdnum:feature/pool-chlorine-setpoint

Conversation

@werdnum

@werdnum werdnum commented Sep 14, 2026

Copy link
Copy Markdown

Home Assistant currently exposes the pool chlorine setpoint as a sensor, but does not provide a number entity to adjust it. This adds pool_chlorine_setpoint_control alongside the existing pH and ORP controls.

The control uses whole steps and controller-reported manual chlorine bounds, falling back to 0–8 when the bounds are unavailable or unusable. It writes through set_pool_chlorine_setpoint() and the existing 0x0066 setpoint command, preserving pH, ORP, acid and spa chlorine values from the live snapshot. Missing preserved values prevent the command from being sent. The existing read-only sensor remains available.

Review fixes included in this branch:

  • Use the same bounds in the UI and client, including controller ranges above the fallback maximum. Reject inverted or zero-width capability ranges as a pair.
  • Reject fractional, non-finite, boolean and out-of-range number input before converting to an integer or sending a command.
  • Validate explicit chlorine changes in the client while retaining byte-level encoding checks for preserved snapshots. Applying a fixed 0–8 limit in the shared packet builder could otherwise regress existing pH/ORP writes on a controller reporting a higher chlorine level.
  • Correct the Home Assistant exception stub so failure-path tests exercise real exception behaviour, remove the integration directory from the test import path to avoid shadowing the standard-library select module, and run the unit suite in CI.
  • Document the control and how to run the tests.

Validation:

  • All 54 isolated unit tests pass with python -m unittest discover -s tests -t . -v.
  • Coverage includes packet framing and preservation of the other settings, zero and maximum values, device capability overrides, malformed ranges, incomplete snapshots, disconnected/unsupported entities, rejected input, and failed sends without optimistic state changes.
  • Integration compilation, JSON metadata parsing, and git diff --check pass locally.

Kept as a draft for hardware validation. The tests stub Home Assistant and mock network sends; they do not establish full HA setup compatibility or controller acceptance/readback. Before marking ready, confirm the control appears with the expected bounds on a live device, a write changes the intended setting while preserving the other four fields, and the vendor app/controller reports the updated value. The 0–8 fallback is retained from the proposed implementation and still needs confirmation for devices without capability data. This represents the manual controller level, not a measured chlorine concentration.

werdnum and others added 2 commits September 14, 2026 12:35
- Define POOL_CHLORINE_SETPOINT bounds (0-8) and validation logic in setpoints.py
- Add set_pool_chlorine_setpoint helper on HaloWebSocketClient to pack all 5 setpoint fields into cmd 0x0066 while preserving existing values
- Register pool_chlorine_setpoint_control number entity in number.py with capability bounds support
- Add unit tests for setpoints validation, WebSocket command construction, and the number platform
Share controller-aware bounds between the number entity and client, reject
fractional/non-finite input before conversion, and validate explicit chlorine
changes without restricting unchanged controller snapshots in pH/ORP writes.

Fix the test exception stub and import path, cover failure paths, and run the
54 isolated unit tests in CI. Document the new control and test limitations.
@werdnum

werdnum commented Sep 15, 2026

Copy link
Copy Markdown
Author

Verification (from Claude)

Hardware validation on a Halo Chlor 45 (fw 2.5, cloud-connected via astralpool_halo_cloud v0.3.0-beta.3 on Home Assistant 2026.8.x), branch head 8330796 applied on top of the beta.3 tag.

Entity

  • number.halo_chlorinator_pool_chlorine_setpoint appears as a slider, min 0 / max 8 / step 1, initial value 4 matching the existing readback sensor.
  • The bounds shown were 0–8. I could not tell whether these came from the controller capability bytes or the fallback, so the "devices without capability data" question is still open from my side.
  • Entity goes unavailable whenever the cloud session drops and returns when it reconnects, same as the pH/ORP controls.

Writes (all via number.set_value, no exceptions logged)

Step Readback sensor Cell level sensor Cell current Notes
Same-value write 4 → 4 4 4 ~3.8 A accepted, no change
4 → 6 6 within 15 s 6 within 15 s 3.78–3.83 A → 5.47–5.53 A within 15 s held for 5+ min, then ~30 min
6 → 4 4 within 15 s 3 then 4 within 30 s 5.49 A → 3.58 A → ~3.8 A held

The cell current step (roughly +44 % for a 4→6 change) and the controller's own level readback both confirm the write reached the unit and changed the manual output level, not just the HA-side state. The intermediate 3 on the way down looks like the controller ramping.

Preserved fields: this unit has no acid doser and no pH/ORP probes, so I cannot confirm those fields survived beyond "no error and the setpoint readback matched". Vendor-app readback not checked (the app and HA kick each other off the single cloud session).

Unit tests: 32 passed locally; the two remaining modules only failed to import because my sandbox Python lacked the websockets package.

@werdnum

werdnum commented Sep 15, 2026

Copy link
Copy Markdown
Author

Reviewed the code manually - ready for maintainer review.

@werdnum
werdnum marked this pull request as ready for review September 15, 2026 00:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T00:45:45.713345Z 8330796 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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