Add automatic script reload support
Features: - Listen for scripts_changed WebSocket messages - Automatically reload integration when scripts change - New on_scripts_changed callback in WebSocket client - Seamless button entity updates without manual reload Technical changes: - Enhanced MediaServerWebSocket with scripts_changed handler - Updated MediaPlayerCoordinator to trigger integration reload - Pass config entry to coordinator for reload capability Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -307,6 +307,7 @@ class MediaServerWebSocket:
|
||||
token: str,
|
||||
on_status_update: Callable[[dict[str, Any]], None],
|
||||
on_disconnect: Callable[[], None] | None = None,
|
||||
on_scripts_changed: Callable[[], None] | None = None,
|
||||
) -> None:
|
||||
"""Initialize the WebSocket client.
|
||||
|
||||
@@ -316,12 +317,14 @@ class MediaServerWebSocket:
|
||||
token: API authentication token
|
||||
on_status_update: Callback when status update received
|
||||
on_disconnect: Callback when connection lost
|
||||
on_scripts_changed: Callback when scripts have changed
|
||||
"""
|
||||
self._host = host
|
||||
self._port = int(port)
|
||||
self._token = token
|
||||
self._on_status_update = on_status_update
|
||||
self._on_disconnect = on_disconnect
|
||||
self._on_scripts_changed = on_scripts_changed
|
||||
self._ws_url = f"ws://{host}:{self._port}/api/media/ws?token={token}"
|
||||
self._session: aiohttp.ClientSession | None = None
|
||||
self._ws: aiohttp.ClientWebSocketResponse | None = None
|
||||
@@ -401,6 +404,10 @@ class MediaServerWebSocket:
|
||||
f"{status_data['album_art_url']}?token={self._token}&t={track_hash}"
|
||||
)
|
||||
self._on_status_update(status_data)
|
||||
elif msg_type == "scripts_changed":
|
||||
_LOGGER.info("Scripts changed notification received")
|
||||
if self._on_scripts_changed:
|
||||
self._on_scripts_changed()
|
||||
elif msg_type == "pong":
|
||||
_LOGGER.debug("Received pong")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user