mqtt: extract shared control topic helpers#345
Merged
MaStr merged 1 commit intoMaStr:mainfrom Apr 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MqttApi to centralize shared MQTT control-topic strings and topic construction logic, reducing duplicated topic concatenation across publish, subscribe, and Home Assistant discovery paths.
Changes:
- Introduced module-level MQTT topic constants and helper methods for building state and command topics.
- Updated publish/discovery/subscription code paths to use
_topic()/_set_topic()instead of repeated string concatenation. - Simplified MQTT discovery-related tests by extracting a shared discovery stub helper.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/batcontrol/mqtt_api.py |
Adds shared topic constants and _topic() / _set_topic() helpers; updates relevant publish/discovery/subscribe call sites to use them. |
tests/batcontrol/test_mqtt_api.py |
Extracts _make_discovery_stub() to reduce repeated test setup for discovery-related assertions. |
MaStr
approved these changes
Apr 23, 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.
This extracts shared MQTT control-topic helpers/constants to reduce repeated magic strings across publish and discovery paths.