Gateway: fix EMS aggregate publish, add debug logging#4133
Merged
Conversation
- Fix EMS aggregate entities (ems_total_*/sub*) never publishing when the EMS unit is not status.inverters[0]. Discovery order is unstable, so the publish path now locates the EMS by type, mirroring automatic_config. - Add opt-in verbose telemetry/plan logging via `gateway_debug: True` in apps.yaml (_debug_dump renders RX telemetry and TX execution plans as text). - Drop the noisy per-cycle plan-capping warning. - Bump version to v8.42.2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a publish-path bug in the Gateway MQTT integration where EMS aggregate dashboard entities could be skipped when the EMS unit was not the first discovered inverter, and it adds an opt-in debug logging facility to dump protobuf telemetry/plan data for troubleshooting.
Changes:
- Fix EMS aggregate entity publishing by locating the EMS inverter by type (rather than assuming
status.inverters[0]). - Add
gateway_debugflag support and_debug_dump()to render RX telemetry / TX execution plans as readable protobuf text. - Bump Predbat version to
v8.42.2and extend gateway test coverage (including a regression for EMS-not-first ordering).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| apps/predbat/gateway.py | Fix EMS aggregate publish selection, add opt-in debug protobuf dumps, adjust plan-entry capping logging behavior. |
| apps/predbat/tests/test_gateway.py | Add regression test for EMS aggregate publishing when EMS isn’t first, plus tests for debug logging and initialization behavior. |
| apps/predbat/predbat.py | Version bump to v8.42.2. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Summary
Fixes a bug where the GivEnergy EMS aggregate dashboard entities never published, plus adds an opt-in debug logging facility for the gateway MQTT telemetry/command flow.
EMS aggregate publish fix
The publish path (
_inject_entities) hard-wired the EMS unit asstatus.inverters[0]. Telemetry discovery order is unstable (cf. the 2026-06-04 incident where a Gateway unit landed at index 0), so when any non-EMS unit appeared first,inv0.type != INVERTER_TYPE_GIVENERGY_EMSand the entireems_total_*/sub*block was silently skipped — even thoughautomatic_configlogged "EMS mode with N sub-inverters" because it correctly locates the EMS by type.The publish path now locates the EMS by type, matching the config path (
inverters = ems_units[:1]).Debug logging
New opt-in
gateway_debug: Trueapps.yaml flag. When enabled,_debug_dumprenders incoming RX telemetry and outgoing TX execution plans as readable protobuf text (with byte sizes). Off by default to avoid log spam.Other
Tests
Added to
test_gateway.py:test_ems_aggregate_entities_when_ems_not_first_inverter— regression for the index-0 bug (AIO at index 0, EMS at index 1).TestDebugLoggingclass — dump-when-enabled, silent-when-disabled, raw-bytes decode, andinitializereads the flag.All 205 gateway tests pass.
🤖 Generated with Claude Code