Skip to content

fix(clone): read circuit energy seeds in the enclosure reference frame - #36

Merged
cayossarian merged 1 commit into
mainfrom
fix/circuit-energy-reference-frame
Jul 31, 2026
Merged

fix(clone): read circuit energy seeds in the enclosure reference frame#36
cayossarian merged 1 commit into
mainfrom
fix/circuit-energy-reference-frame

Conversation

@cayossarian

@cayossarian cayossarian commented Jul 31, 2026

Copy link
Copy Markdown
Member

Companion to ebus-emitter 0.2.1, which corrected the same inversion on the publish side.

The bug

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), imported-energy is 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-energy into "consumed", and the emitter published "consumed" back out as imported-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.pyinitial_consumed_energy_wh now seeds from exported-energy and initial_produced_energy_wh from imported-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 rising imported-energy and the backfeeding solar circuit a rising exported-energy, the reverse of what a real panel publishes. One comment also described positive active-power as "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

  • 241 tests pass
  • ruff check clean, mypy clean (58 source files, no ignores added)
  • pre-commit hooks pass, including sync-version across all four version references

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
cayossarian force-pushed the fix/circuit-energy-reference-frame branch from c274532 to 0e56e7e Compare July 31, 2026 22:34
@cayossarian
cayossarian merged commit 628c988 into main Jul 31, 2026
2 checks passed
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