Skip to content

mqtt: extract shared control topic helpers#345

Merged
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:mqtt-topic-helpers
Apr 23, 2026
Merged

mqtt: extract shared control topic helpers#345
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:mqtt-topic-helpers

Conversation

@filiplajszczak
Copy link
Copy Markdown
Contributor

This extracts shared MQTT control-topic helpers/constants to reduce repeated magic strings across publish and discovery paths.

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 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 MaStr merged commit 352eee7 into MaStr:main Apr 23, 2026
14 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