-
Notifications
You must be signed in to change notification settings - Fork 1
Add WebSocket integration and space state notifications #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WebSocket integration and space state notifications #413
Conversation
…xt and remove duplicate function definition - Updated logger naming to include interface class name for better traceability. - Relocated `get_reserved_parameter_names` function
- Introduced `WebsocketEventInterface` and `WebsocketEventHandler` for managing WebSocket events. - Added `websockets` dependency in `pyproject.toml` and `uv.lock` for WebSocket functionality. - Created `WebsocketPluginIntegration` for plugin lifecycle management of WebSocket routers. - Updated Bolt request handling to include WebSocket event type. - Enhanced plugin lifecycle to initialize and finalize WebSocket routes seamlessly.
- Introduced `/ws/space/state` WebSocket endpoint to broadcast space state changes to clients. - Enabled real-time space state updates via new `inform_websocket_clients_of_space_state_change` helper. - Updated space state open/close logic to notify connected WebSocket clients.
- Deleted `space state ws.py` as it is no longer used or required in the project.
|
This small script allows a connection to the import asyncio
import json
from asyncio import CancelledError
import websockets
HOST = "smib-pi:80"
async def listen():
uri = f"ws://{HOST}/ws/space/state"
async with websockets.connect(uri) as websocket:
print("Connected to WebSocket")
while True:
try:
message = await websocket.recv()
data = json.loads(message)
print("Received:", data)
except websockets.ConnectionClosed:
print("Connection closed")
break
try:
asyncio.run(listen())
except (CancelledError, KeyboardInterrupt):
print("WebSocket listener stopped") |
…-the-httpevent-interfacehandlerservice
…-the-httpevent-interfacehandlerservice
…pport - Added WebSocket details, including real-time updates and endpoint usage. - Clarified Traefik reverse proxy routes with examples for all SMIB services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds first-class WebSocket support and real-time space state notifications. Key updates integrate a WebSocket event interface/handler, expose a new /ws endpoint, and unify event typing across HTTP/Scheduled/WebSocket flows.
- Introduces WebsocketEventInterface and WebsocketEventHandler to register and dispatch WebSocket events via Bolt.
- Adds /ws/space/state to push real-time space state to connected clients and a helper to broadcast updates.
- Aligns event types via BoltEventType and standardizes router finalization naming.
Reviewed Changes
Copilot reviewed 17 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/smib/plugins/integrations/websocket_plugin_integration.py | New plugin integration to register and remove WebSocket routes and include routers into FastAPI. |
| src/smib/plugins/integrations/http_plugin_integration.py | Logger improvement and method rename to finalise_router_setup for consistency. |
| src/smib/events/interfaces/websocket_event_interface.py | Adds decorator and routing for WebSocket endpoints with Bolt dispatch wiring. |
| src/smib/events/interfaces/scheduled_event_interface.py | Switches scheduled events to use BoltEventType/BoltRequestMode constants. |
| src/smib/events/interfaces/http/init.py | Refactors to shared parameter extraction, type fixes, and unified event typing. |
| src/smib/events/interfaces/init.py | New shared helpers for reserved names and parameter extraction. |
| src/smib/events/handlers/websocket_event_handler.py | New handler to transform WebSocket connections into Bolt requests. |
| src/smib/events/handlers/scheduled_event_handler.py | Uses BoltEventType for scheduled event payloads. |
| src/smib/events/handlers/http_event_handler.py | Minor typing/cleanup and unified event typing. |
| src/smib/events/handlers/init.py | Adds WEBSOCKET mode and removes unused Clock import. |
| src/smib/events/init.py | Centralizes BoltEventType definitions. |
| src/smib/main.py | Wires WebSocket interface/handler/integration into the app and plugin lifecycle. |
| src/plugins/space/spacestate/listeners/websocket.py | New WebSocket listener and broadcast helper for space state. |
| src/plugins/space/spacestate/common.py | Notifies WebSocket clients when the space state changes. |
| pyproject.toml | Adds websockets dependency. |
| README.md | Documents WebSocket capability and routing layout. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
… inclusion logic - Enhanced `extract_parameter_and_value` and `find_annotation_in_signature` for better type handling and annotations. - Modified `APIRouter` initialization to exclude schema for individual routers. - Adjusted router finalization to include schema in FastAPI app.
…-the-httpevent-interfacehandlerservice
…-the-httpevent-interfacehandlerservice
…-the-httpevent-interfacehandlerservice
|
I will update the README once the websocket PR is merged. Format changes a bit and can't be bothered with the merge conflicts |
sjefferson99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Container builds, examples script correctly provides state changes in real time as expected.
Summary
This pull request introduces WebSocket support and integrates real-time space state notifications and updates. Key changes include:
/ws/space/stateWebSocket endpoint for broadcasting space state changes.inform_websocket_clients_of_space_state_changehelper for real-time updates.WebsocketEventInterfaceandWebsocketEventHandlerfor WebSocket event management.