Repository navigation
Reconstruct misaligned power, diagnostic, and runtime metrics - #37
Open
Moustachauve wants to merge 6 commits into
Open
Moustachauve wants to merge 6 commits into
Moustachauve wants to merge 6 commits into
Conversation
Previous electrical and runtime fields assumed fixed-point scaling (/ 2560.0 for current and / 32.0 for voltage), which produced nonsensical values such as idle heater draw while the heater was off and negative pump runtimes after 97 days. Controlled live load testing alongside utility smart-meter measurements revealed that the Home Network Adapter's JSON output has a byte-alignment offset across adjacent little-endian values: 16-bit electrical registers are split across neighboring keys in /status and /addDebugData, and 24-bit runtime counters are shifted into adjacent status fields. Reconstructing the split bytes into a unified PowerMetrics model on Spa exposes per-circuit apparent/real power, whole-amp currents, and total power without leaking raw endpoint boundaries to callers. Idle and pump-only power resolve directly from /status alone, so HotSpring.update() only polls /addDebugData when active heater or Jet 3 loads require its upper bytes on spas equipped with current sensors, avoiding extra LoRA radio round-trips when idle or on entry-level boards without current sensing. Partial command echoes and unpaired status updates preserve or invalidate active load readings without pairing bytes from different polls. As a breaking cleanup for v5.0.0, the misdecoded current, voltage, and runtime attributes on Heater, Jet, SpaTestData, and Diagnostics have been removed or replaced. Runtime counters are now routed to the components they actually measure (Jet 1, Jet 3, Blower, and Spa.system_uptime_seconds), SpaTestData retains only calibration fields, and Diagnostics exposes the decoded voltage indicator, clean-cycle flag, and filter cycle durations.
Short abbreviations for misaligned register words made the byte-reconstruction logic harder to read, and the new power and client tests duplicated assertions across multi-step scenarios and HTTP mocks. Use descriptive full-word names across models and test helpers, consolidate power and runtime cases into single-step parametrized snapshot tests, preserve cached diagnostics on empty debug polls, and skip opportunistic debug polling while the spa link is disconnected.
Current sensors stayed unpopulated while idle or running Jet 1/2/blower, and malformed optional /addDebugData responses or back-to-back diagnostic polls could fail update() or pair stale /status bytes. Fetch /addDebugData once for baseline small-loads current and while any pump or heater load is active, suppress non-critical debug parse errors during update(), guard cross-endpoint heater pairing across partial updates, and clean up dead casts and jet iteration helpers.
Separate word containers, decoding helpers, and per-field gating duplicated the layout of a single contiguous stream of register words and added unnecessary state flags and test boilerplate. Walk the 10-word sequence and runtime routes from mapping tables, replace separate electrical state fields with use-once pending status words, deduplicate client debug fetching and hour conversion, and streamline model and snapshot tests.
The 8-bit indicator extracted from L1_N_Volts reflects an uncalibrated ADC threshold rather than true 256 V mains voltage, leaving it stuck True on a ~248 V residential feed while staying False elsewhere. Dropping Diagnostics.l2_voltage_above_256v avoids surfacing a misleading binary state in Home Assistant. Also simplify power reconstruction and its test suite after review: decouple _parse_diagnostics_and_electrical from /status words so register decoding happens in Spa.update_diagnostics, remove the from_status flag and _MISSING sentinel, assert default PowerMetrics inline rather than snapshotting unsupported boards, and flatten stale-word tests.
Moustachauve
marked this pull request as ready for review
November 19, 2026 04:48
Remove the redundant dict default on small_loads_power after full /status decoding, and add test cases covering Blower.on_hours, incomplete test_data.status payloads, and parametrized total_power cases per reviewer feedback.
This branch has not been deployed
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.
Previous electrical and runtime fields assumed fixed-point scaling (/ 2560.0 for current and / 32.0 for voltage), which produced nonsensical values such as idle heater draw while the heater was off and negative pump runtimes after 97 days. Controlled live load testing alongside utility smart-meter measurements revealed that the Home Network Adapter's JSON output has a byte-alignment offset across adjacent little-endian values: 16-bit electrical registers are split across neighboring keys in /status and /addDebugData, and 24-bit runtime counters are shifted into adjacent status fields.
Reconstructing the split bytes into a unified PowerMetrics model on Spa exposes per-circuit apparent/real power, whole-amp currents, and total power without leaking raw endpoint boundaries to callers. On spas with current sensors, HotSpring.update() only polls /addDebugData once for baseline small_loads_current or while active loads (heater, Jet 1, Jet 2, Jet 3, or blower) are running, skipping extra LoRA round-trips when idle once synced and on entry-level boards without current sensing. Partial command echoes and unpaired status updates preserve or invalidate active load readings without pairing bytes from different polls.
As a breaking cleanup for v5.0.0, the misdecoded current, voltage, and runtime attributes on Heater, Jet, SpaTestData, and Diagnostics have been removed or replaced. Runtime counters are now routed to the components they actually measure (Jet 1, Jet 3, Blower, and Spa.system_uptime_seconds), SpaTestData retains only calibration fields, and Diagnostics exposes decoded Jet 3 voltage, the daily clean-cycle setting, and filter cycle durations.