feat(plugins): bidirectional plugin-frontend WebSocket channel#6818
Merged
Conversation
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.
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.
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 toplugin:<PluginKey>; non-blocking.onWebSocketMessage(self, Data)— optional plugin callback receiving commands sent from the frontend.HardwareID; commands can target one instance viahwid.Frontend
livesocketgainssubscribePlugin/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.wikiupdated.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.