Skip to content

Add Per-Circuit Pump Speed Control via NumberEntity Sliders#66

Open
celestinjr wants to merge 3 commits into
Crewski:mainfrom
celestinjr:feat/pump-speed-control
Open

Add Per-Circuit Pump Speed Control via NumberEntity Sliders#66
celestinjr wants to merge 3 commits into
Crewski:mainfrom
celestinjr:feat/pump-speed-control

Conversation

@celestinjr

Copy link
Copy Markdown

Description

This PR adds per-circuit speed/flow control for variable-speed pumps in the njsPC-HA custom integration. Users can now adjust individual pump circuit speeds (RPM) or flow rates (GPM) directly from Home Assistant using slider controls.

Changes

Core Implementation:

  • custom_components/njspc_ha/pumps.py — New PumpCircuitSpeedNumber entity class:

    • Extends PoolEquipmentEntity and NumberEntity for per-circuit speed/flow control
    • Detects unit type (RPM vs GPM) from circuit configuration
    • Implements async_set_native_value() to send commands via config/pumpCircuit API endpoint
    • Updates state reactively from pumpExt events without polling
    • Respects min/max/step constraints from pump configuration
  • custom_components/njspc_ha/init.py — Coordinator updates:

    • Added socket.io listener for pumpExt event to receive extended pump/circuit data
    • Maps event data including all circuit states
  • custom_components/njspc_ha/const.py — New constants:

    • API_PUMP_CIRCUIT = "config/pumpCircuit" — API endpoint for setting speed/flow
    • EVENT_PUMP_EXT = "pumpExt" — Socket event for extended pump circuit data
  • custom_components/njspc_ha/number.py — Platform setup:

    • Instantiates PumpCircuitSpeedNumber for each pump circuit that supports speed or flow control
    • Filters to pumps with maxSpeed or maxFlow capabilities

Tests (tests/test_pump_circuit_speed.py):

  • Comprehensive TDD suite with 40+ test cases covering:
    • Initialization from pump/circuit config (RPM vs GPM detection, min/max/step inference)
    • NumberEntity properties (names, units, unique IDs, icon/mode)
    • API command generation for speed and flow updates
    • Reactive updates from pumpExt events
    • Availability state propagation
    • Edge cases (missing config, empty circuit arrays, wrong pump/circuit IDs)
    • Multi-circuit independence testing

Features

RPM Control — For variable-speed pumps with speed control
Flow Control — For pumps reporting flow in GPM
Slider UI — Home Assistant number entity slider for intuitive control
Live Updates — State updates from pumpExt events without polling
Constraints — Respects pump min/max speeds and step sizes
Multi-Circuit — Each pump circuit gets independent control entity
Availability — Gracefully handles connection loss

Testing Checklist

  • Run test suite: pytest tests/test_pump_circuit_speed.py -v
  • Manual test in Home Assistant:
    • Verify slider entities appear for each variable-speed pump circuit
    • Test adjusting speed/flow via slider — confirm command is sent
    • Monitor njsPC logs to verify config/pumpCircuit API calls
    • Verify entity state updates when pump circuit changes externally
    • Verify unavailable state when njsPC connection is lost
  • Check Home Assistant entity registry for correct unique IDs
  • Test with multiple pump circuits on same pump

Breaking Changes

None — this is purely additive functionality.

Dependencies

Depends on #62. Please merge that fix first for cleaner history.

Related Issues

None

…nd==10

PumpOnSensor relied on command==10 to determine if a pump is running.
This is incorrect for Regal Modbus pumps, which emit command=4 while
actively running (e.g. rpm=3450, watts=1406, command=4), causing the
running state sensor to incorrectly toggle off/on with each state update.

Fix: for non-relay pumps, use rpm>0 or watts>0 as the running indicator.
Relay-based pumps retain existing relay>0 logic.

Aligns with the same fix applied in nodejs-poolController-dashPanel.
Implement intelligent throttling for high-frequency push-driven sensors across
the integration (pump, temperature, filter sensors). Reduces HomeAssistant/InfluxDB writes
while preserving responsiveness through configurable delta-based and binary
throttling modes. Also fixes PumpSpeedSensor max_speed scalar bug.
- Add pumpExt Socket.IO event listener to receive extended pump data with circuits
- Add EVENT_PUMP_EXT and API_PUMP_CIRCUIT constants
- Implement PumpCircuitSpeedNumber(NumberEntity) for variable-speed pump circuits
  - One entity per circuit per pump that supports speed/flow control
  - RPM mode (default) or GPM mode based on circuit units field
  - Uses PUT /config/pumpCircuit API to set speed/flow
  - Slider mode UI for intuitive adjustment
  - Listens to pumpExt events for push updates from external changes
  - Optimistic updates for responsive UX
- Wire up entity creation in number.py to iterate pump circuits
- Add comprehensive TDD test suite (40 tests) covering:
  - Initialization and property mapping
  - RPM vs GPM unit handling
  - API calls with correct payload structure
  - Coordinator updates via pumpExt event
  - Availability handling
  - Edge cases (missing circuits, empty arrays, wrong pump/circuit IDs)
- All 71 tests passing with zero regressions
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