fix: make WebSocket path configurable for EMQX compatibility - #307
fix: make WebSocket path configurable for EMQX compatibility#307bplein wants to merge 3 commits into
Conversation
The hardcoded path "/" caused WebSocket handshakes to fail with EMQX, which serves MQTT over WebSocket at /mqtt. Add a ws_path config option (defaulting to /mqtt) so the integration works with both EMQX and broker deployments that use a different WebSocket path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
| client_id_prefix: str | ||
| topic_status: str | ||
| topic_packets: str | ||
| ws_path: str = "/mqtt" |
There was a problem hiding this comment.
The existing default was / and this changes the new default to /mqtt. It might make sense to change the default to / unless we know that /mqtt is what most users are already using.
There was a problem hiding this comment.
That does make sense. I’ll make the change today.
There was a problem hiding this comment.
There were additional places where this incorrect default was set. Fixed and tested with 4f79a85
Co-authored-by: Andy Shinn <andys@andyshinn.as>
Initial commits defaulted to /mqtt, these revert it to default to / which is the old behavior.
|
Converted to draft, unexpected issue I need to resolve on my end (may not be related to the PR itself) |
|
Errors were configuration issues on EMQX. |
awolden
left a comment
There was a problem hiding this comment.
Looks good, one thing before merge: add ws_path to the mqtt_broker step in translations/en.json (data + data_description), otherwise the form renders the raw key. While you're in there: .strip() or "/" instead of or "/").strip() so whitespace input falls back too, and the indentation on that ).strip() line is off. README lines could use a quick reword and have trailing whitespace.
Summary
/mqttinstead of/ws_pathbroker config option (default:/for backwards compatibility)/on next save, maintaining compatibility with most broker deployments.Context
The hardcoded
ws_set_options(path="/", ...)caused the Home Assistant integration to fail when connecting to EMQX, which expects WebSocket connections at the/mqttpath. This is the default WebSocketendpoint for EMQX deployments.
Changes
mqtt_uploader.py: Addedws_pathfield toBrokerConfigwith default/mqtt_uploader.py: Passws_pathfrom broker settings when creatingBrokerConfigmqtt_uploader.py: Usebroker.ws_pathinstead of hardcoded/inws_set_optionsconfig_flow.py: Addedws_pathfield to broker config UI formconfig_flow.py: Persistws_pathvalue when saving broker configurationTesting
/mqttws_pathdefault to/Admission of Guilt