mqtt: publish control source state#354
Merged
MaStr merged 1 commit intoMaStr:mainfrom Apr 27, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new diagnostic MQTT state topic that indicates whether the currently applied control state was last selected by Batcontrol’s optimizer loop or via the MQTT API override path.
Changes:
- Add a new MQTT state topic
/control_sourceplus Home Assistant MQTT discovery for a diagnostic sensor. - Track and publish
last_control_sourcefrom the core control path (optimizer-drivenrun()vs API-drivenapi_set_*()methods). - Extend unit tests to cover discovery + publishing behavior and core publishing semantics.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/batcontrol/mqtt_api.py |
Adds TOPIC_CONTROL_SOURCE, publish_control_source(), and HA discovery entry for the new diagnostic sensor. |
src/batcontrol/core.py |
Introduces control source constants, tracks last_control_source, and publishes it on optimizer/API actions and via refresh_static_values(). |
tests/batcontrol/test_mqtt_api.py |
Adds tests ensuring HA discovery contains the new diagnostic sensor and that publish uses the correct topic. |
tests/batcontrol/test_core.py |
Adds tests verifying optimizer/API paths set and publish the expected control source. |
d2fa298 to
84c9694
Compare
MaStr
requested changes
Apr 27, 2026
Owner
|
Just realized I need to publish "request change" to get my review published |
84c9694 to
25af81e
Compare
Owner
|
I had an if on the setter in my mind to just return of new = old |
MaStr
approved these changes
Apr 27, 2026
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.
Publishes a diagnostic MQTT state showing whether the current control state was last selected by the optimizer or through batcontrol's MQTT API.