Skip to content

mqtt: publish control source state#354

Merged
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:mqtt-control-source-state
Apr 27, 2026
Merged

mqtt: publish control source state#354
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:mqtt-control-source-state

Conversation

@filiplajszczak
Copy link
Copy Markdown
Contributor

Publishes a diagnostic MQTT state showing whether the current control state was last selected by the optimizer or through batcontrol's MQTT API.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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_source plus Home Assistant MQTT discovery for a diagnostic sensor.
  • Track and publish last_control_source from the core control path (optimizer-driven run() vs API-driven api_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.

Comment thread src/batcontrol/mqtt_api.py Outdated
@filiplajszczak filiplajszczak force-pushed the mqtt-control-source-state branch from d2fa298 to 84c9694 Compare April 27, 2026 15:02
Comment thread src/batcontrol/core.py
@MaStr
Copy link
Copy Markdown
Owner

MaStr commented Apr 27, 2026

Just realized I need to publish "request change" to get my review published

@filiplajszczak filiplajszczak force-pushed the mqtt-control-source-state branch from 84c9694 to 25af81e Compare April 27, 2026 15:46
@filiplajszczak filiplajszczak requested a review from MaStr April 27, 2026 15:49
@MaStr
Copy link
Copy Markdown
Owner

MaStr commented Apr 27, 2026

I had an if on the setter in my mind to just return of new = old

@MaStr MaStr merged commit 87cada9 into MaStr:main Apr 27, 2026
10 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.

3 participants