fix(sunsynk,deye): own the power sign flags instead of inheriting them - #4618
Merged
Conversation
base.args is a single shared dict and is NOT namespaced per inverter type, so whichever component sets grid_power_invert sets it for every inverter index on the install. teslemetry and fox both set it True for their own hardware, quite correctly - and a Sunsynk or DEYE inverter that never claimed the key inherited that flip. The effect on an install running Sunsynk alongside either of them: the component publishes a correct grid sensor (+506 W while exporting, verified live), then inverter.py negates it again on the inherited flag, so the export reads as an import and the power-flow arrow points the wrong way. All three flags are now set explicitly to False, because publish_data already emits Predbat's conventions - grid negative on import (SUNSYNK_TELEMETRY_NEGATE / DEYE_TELEMETRY_NEGATE), battery positive on discharge, load positive - each confirmed live. Setting them rather than relying on the default is the point: a default only applies when nothing else has written the key, which is exactly the case that was failing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a cross-component configuration leak where grid_power_invert/battery_power_invert/load_power_invert could be unintentionally inherited via the shared base.args dict, causing Sunsynk and Deye power-flow signs to be flipped after publishing already-correct sensor values.
Changes:
- Explicitly sets
grid_power_invert,battery_power_invert, andload_power_inverttoFalseinautomatic_config()for Sunsynk and Deye so they always “own” these flags. - Adds regression tests for both components to ensure all three flags are always set and are per-inverter lists (one entry per inverter index).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/predbat/sunsynk.py | Sets all three invert flags explicitly to False during Sunsynk auto-discovery to prevent inherited sign flips. |
| apps/predbat/deye.py | Sets all three invert flags explicitly to False during Deye auto-discovery to prevent inherited sign flips. |
| apps/predbat/tests/test_sunsynk_config.py | Adds a regression test asserting the invert flags are claimed and correctly sized per inverter. |
| apps/predbat/tests/test_deye_publish.py | Adds a regression test asserting the invert flags are claimed and correctly sized per inverter. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
The bug
base.argsis a single shared dict and is not namespaced per inverter type, so whichever component setsgrid_power_invertsets it for every inverter index on the install.teslemetry.py:646andfox.py:2235both set itTruefor their own hardware — quite correctly. Sunsynk and Deye never claimed the key at all, so on an install running either of those alongside them, they inherited the flip:Verified live that the component itself publishes the correct sign — raw
pac−506 with the day's counters at 0.0 kWh imported against 10.7 kWh exported, published as +506, which is Predbat's documented convention (negative import, positive export). So the sensor was right and the flag was flipping it afterwards.The fix
Both components now set
grid_power_invert,battery_power_invertandload_power_invertexplicitly toFalseinautomatic_config.Setting them rather than relying on the default is the whole point: a default only applies when nothing else has written the key, which is exactly the case that was failing.
Falseis right for all three becausepublish_dataalready emits Predbat's conventions — grid negative on import (SUNSYNK_TELEMETRY_NEGATE/DEYE_TELEMETRY_NEGATE), battery positive on discharge, load positive — each confirmed against live hardware.Testing
A regression test per component asserting all three flags are claimed with one entry per inverter, so neither can silently go back to inheriting. Full
--quicksuite green, pre-commit clean.🤖 Generated with Claude Code