Updated the MQTT component to optionally filter its messages by topic paths#3321
Updated the MQTT component to optionally filter its messages by topic paths#3321sfeilmeier merged 5 commits intoOpenEMS:developfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds topic filtering functionality to the MQTT component, allowing users to selectively publish only certain topics that match specified patterns. It introduces a new configuration option for filtering and changes the publish method to support filtered publishing status.
- Added a
filterSpecconfiguration parameter that accepts semicolon-delimited MQTT topic patterns using wildcards (+ and #) - Modified the publish mechanism to return an enum status instead of boolean, supporting OK, ERROR, and FILTERED states
- Implemented pattern matching logic to filter topics before publishing to the broker
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Config.java | Added new filterSpec configuration attribute for topic filtering |
| MqttPublishStatus.java | New enum to represent publish operation status (OK, ERROR, FILTERED) |
| ControllerApiMqttImpl.java | Implemented filtering logic and updated publish methods to return status enum |
| SendChannelValuesWorker.java | Updated to handle new publish status enum and improved logging |
| ControllerApiMqtt.java | Removed trailing slashes from topic constants |
| MyConfig.java | Added test implementation for new filterSpec method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (33.34%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #3321 +/- ##
=============================================
- Coverage 59.53% 59.51% -0.02%
Complexity 113 113
=============================================
Files 2765 2767 +2
Lines 119513 119579 +66
Branches 8892 8906 +14
=============================================
+ Hits 71142 71156 +14
- Misses 45697 45745 +48
- Partials 2674 2678 +4 🚀 New features to boost your workflow:
|
io.openems.edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/Config.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
....edge.controller.api.mqtt/src/io/openems/edge/controller/api/mqtt/ControllerApiMqttImpl.java
Outdated
Show resolved
Hide resolved
io.openems.edge.controller.api.mqtt/test/io/openems/edge/controller/api/mqtt/MyConfig.java
Outdated
Show resolved
Hide resolved
* Apply requested changes from review * Add MqttTopicFilter and unit tests
Fork of #1503 by @JohnVidler