Skip to content

feat(plugins): bidirectional plugin-frontend WebSocket channel#6818

Merged
gizmocuz merged 5 commits into
developmentfrom
feature/plugin-websocket-channel
May 16, 2026
Merged

feat(plugins): bidirectional plugin-frontend WebSocket channel#6818
gizmocuz merged 5 commits into
developmentfrom
feature/plugin-websocket-channel

Conversation

@gizmocuz

Copy link
Copy Markdown
Contributor

Summary

Adds a bidirectional WebSocket channel between Python plugins and the web frontend.

  • Domoticz.WebSocketSend(payload) — push a dict (JSON, full 64-bit int support) or string to frontend clients subscribed to plugin:<PluginKey>; non-blocking.
  • onWebSocketMessage(self, Data) — optional plugin callback receiving commands sent from the frontend.
  • Messages fan out across all running instances of a plugin and carry the originating HardwareID; commands can target one instance via hwid.
  • Thread-safe instance registry with framework-driven lifecycle cleanup; Python-free bridge for non-blocking inbound delivery; rights check + 64 KiB payload cap on inbound commands.

Frontend

livesocket gains subscribePlugin / unsubscribePlugin / sendPluginCommand / onPluginMessage, with reconnect re-subscription and idempotent subscribe.

Example, tests, docs

  • plugins/examples/WebSocketChannelTest/ — example plugin + Forecast.html-style custom page (ping→pong, multi-instance fan-out, MeshCore-style atomic template install/remove).
  • test/python/test_plugin_websocket.py — 15-check end-to-end suite (fan-out, hwid tagging, payload forms, round-trip, topic filtering, unknown-plugin handling, >2^31 integer regression guard).
  • docs/Developing_a_Python_plugin.wiki updated.

Verification

Implemented across F0–F7 with code-review gates per phase, then debugged and certified on a live Domoticz instance: end-to-end test 15/15 passing.

gizmocuz added 5 commits May 16, 2026 10:36
Plugins can push arbitrary JSON to subscribed frontend clients via Domoticz.WebSocketSend() and receive commands via an onWebSocketMessage(self, Data) callback. Messages fan out across all running instances of a plugin (topic plugin:<key>) and carry the originating HardwareID. Includes a thread-safe instance registry with framework-driven lifecycle cleanup, a Python-free bridge for non-blocking inbound delivery, 64-bit integer support in the Python-to-JSON conversion, and the DelayedLink shim entry for PyLong_AsUnsignedLongLong.
subscribePlugin/unsubscribePlugin/sendPluginCommand/onPluginMessage helpers with reconnect re-subscription, idempotent subscribe, client-side payload cap and a selectable message dispatch.
Demonstrates WebSocketSend, ping->pong via onWebSocketMessage, multi-instance fan-out, atomic concurrency-safe template install/remove (MeshCore-style), and a Forecast.html-style AngularJS custom page.
15-check live suite covering fan-out, hwid tagging, payload forms, round-trip, topic filtering, unknown-plugin handling and a >2^31 integer regression guard.
@gizmocuz gizmocuz merged commit a6f6184 into development May 16, 2026
2 checks passed
@gizmocuz gizmocuz deleted the feature/plugin-websocket-channel branch May 16, 2026 08:39
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.

1 participant