feat: add GatewayMQTT component for ESP32 MQTT integration#3557
Open
feat: add GatewayMQTT component for ESP32 MQTT integration#3557
Conversation
… plan Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… decode and commands Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GatewayMQTT now inherits from ComponentBase with full instance methods: - initialize() stores config and builds MQTT topic strings - run() starts background MQTT listener on first call, does housekeeping after - _mqtt_loop() connects with TLS, subscribes to /status and /online, reconnects - _process_telemetry() decodes protobuf and publishes entities via set_state_wrapper - publish_plan/publish_command for outbound control - is_alive() checks MQTT connected + telemetry freshness - select_event/number_event for UI-driven mode/rate/SOC changes - final() sends AUTO mode and cancels listener on shutdown - Token refresh via Supabase edge function (same pattern as OAuthMixin) All existing static methods and tests preserved unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ewal Add extract_jwt_expiry and token_needs_refresh static methods. Wire into _check_token_refresh to extract expiry from JWT claims directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…erter entities Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix MQTT topic prefix: gw/ -> predbat/devices/ (critical) - Add retain=True on schedule topic publish - Set api_started=True on first telemetry decode - Add get_error_count() with error tracking - Fix edge function name: refresh-mqtt-token (matching spec) - Remove unused _TOKEN_REFRESH_THRESHOLD constant Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consistent with Fox OAuth pattern — single oauth-refresh edge function handles all providers including gateway MQTT token refresh. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
oauth-refresh edge function reads refresh token from instance secrets, so the component doesn't need to hold or pass it. Consistent with how Fox OAuth works via OAuthMixin. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
Code Review: GatewayMQTT ComponentVerdict: Approve Correctness
Minor Issues (follow-up)
Test Coverage12 tests covering protobuf round-trip, entity mapping, plan serialization, command format, EMS entities, and JWT token handling. Good coverage for v1. 🤖 Generated with Claude Code |
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
GatewayMQTTcomponent (gateway.py) providing full inverter telemetry and control via ESP32 gateway MQTT/protobuf interfaceGatewayStatus(telemetry) andExecutionPlan(schedule) inproto/COMPONENT_LISTwithpredbat_gateway_event filter, phase 1aiomqttlistener with TLS, exponential backoff reconnectoauth-refreshedge function (same pattern as Fox OAuth)Test plan
pytest tests/test_gateway.py -v— 11 pass, 1 skipped (no aiomqtt locally)/scheduletopic with retain🤖 Generated with Claude Code