Skip to content

Gateway: fix EMS aggregate publish, add debug logging#4133

Merged
springfall2008 merged 2 commits into
mainfrom
fix/gateway_misc
Jun 26, 2026
Merged

Gateway: fix EMS aggregate publish, add debug logging#4133
springfall2008 merged 2 commits into
mainfrom
fix/gateway_misc

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

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 as status.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_EMS and the entire ems_total_* / sub* block was silently skipped — even though automatic_config logged "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: True apps.yaml flag. When enabled, _debug_dump renders incoming RX telemetry and outgoing TX execution plans as readable protobuf text (with byte sizes). Off by default to avoid log spam.

Other

  • Drop the noisy per-cycle plan-capping warning.
  • Bump version to v8.42.2.

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).
  • New TestDebugLogging class — dump-when-enabled, silent-when-disabled, raw-bytes decode, and initialize reads the flag.

All 205 gateway tests pass.

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings June 26, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_debug flag support and _debug_dump() to render RX telemetry / TX execution plans as readable protobuf text.
  • Bump Predbat version to v8.42.2 and 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.

Comment thread apps/predbat/gateway.py Outdated
Comment thread apps/predbat/gateway.py
Comment thread apps/predbat/gateway.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008 springfall2008 merged commit 2aa2ddd into main Jun 26, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/gateway_misc branch June 26, 2026 11:05
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.

2 participants