fix(clone): read circuit energy seeds in the enclosure reference frame - #36
Merged
Merged
Conversation
clone.py seeded initial_consumed_energy_wh from a scraped panel's imported-energy and initial_produced_energy_wh from its exported-energy. The wire is enclosure-framed: exported-energy is energy the enclosure exported TO a circuit (normal load consumption) and imported-energy is energy it imported FROM a circuit (backfeed). Both the initial-translation path and the refresh path now read them the correct way round. This is the companion to ebus-emitter 0.2.1, which corrected the same inversion on the publish side. The two were previously wrong in a mutually cancelling way — clone read imported-energy into "consumed" and the emitter published "consumed" back out as imported-energy — so a cloned panel round-tripped its wire values faithfully while every value carried the wrong meaning. Fixing only one side breaks the round-trip, so they move together. The test fixtures carried the same inversion: a load circuit was given a rising imported-energy and a backfeeding solar circuit a rising exported-energy, the reverse of what a real panel publishes, and one comment described positive active-power as "export" when on the wire it means the enclosure is importing from the circuit. Fixtures and the two energy-seeding test names now describe the enclosure frame. Requires ebus-emitter >= 0.2.1.
cayossarian
force-pushed
the
fix/circuit-energy-reference-frame
branch
from
July 31, 2026 22:34
c274532 to
0e56e7e
Compare
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.
Companion to
ebus-emitter0.2.1, which corrected the same inversion on the publish side.The bug
clone.pyseededinitial_consumed_energy_whfrom a scraped panel'simported-energyandinitial_produced_energy_whfrom itsexported-energy.The wire is enclosure-framed:
exported-energyis energy the enclosure exported to a circuit (normal load consumption),imported-energyis energy it imported from a circuit (backfeed). So both were read backwards.Why it went unnoticed
The two repos were wrong in a mutually cancelling way — clone read
imported-energyinto "consumed", and the emitter published "consumed" back out asimported-energy. A cloned panel therefore round-tripped its wire values faithfully while every value carried the wrong meaning. Nothing looked broken from inside the simulator.It only became visible from outside: the SPAN HA integration, which reads the enclosure frame correctly, displayed every load circuit as producing energy and consuming none.
Fixing only one side breaks the round-trip, which is why these two changes move together.
What changed
clone.py—initial_consumed_energy_whnow seeds fromexported-energyandinitial_produced_energy_whfromimported-energy, in both the initial-translation path (_translate_circuit) and the refresh path (update_config_from_scrape).config_types.py— the field comments described the old (wrong) sources.tests/test_clone.py— the fixtures encoded the same inversion: a load circuit had a risingimported-energyand the backfeeding solar circuit a risingexported-energy, the reverse of what a real panel publishes. One comment also described positiveactive-poweras "export", when on the wire it means the enclosure is importing from the circuit. Fixtures, comments, and the two energy-seeding test names now describe the enclosure frame.Requires
ebus-emitter >= 0.2.1. Pairing this release with an older emitter reinstates the inversion.
This PR deliberately does not add a version guard for that. An earlier revision enforced a minimum emitter version in
scripts/dev-setup.sh, but the emitter is being vendored into this repo as a follow-up — the fork is permanent, so an external path dependency no longer buys anything and the add-on image cannot install it at all. Vendoring removes the cross-repo lockstep problem outright rather than policing it, so the guard was dropped rather than landing days before its deletion.Upgrade note
Existing cloned configs keep their
initial_*values; those seeds were captured under the old reading, so a re-clone is needed for them to carry the right meaning.Verification
ruff checkclean,mypyclean (58 source files, no ignores added)sync-versionacross all four version references