mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-08 09:46:29 +00:00
Proxy WebSocket close messages as well (#4942)
We can "proxy" WebSocket close messages just as well as any other WebSocket message. This avoids an error print in the Supervisor logs whenever any one side of the connection closes.
This commit is contained in:
parent
3a2c3e2f84
commit
bb5e138134
@ -186,6 +186,9 @@ class APIProxy(CoreSysAttributes):
|
|||||||
return await target.send_str(msg.data)
|
return await target.send_str(msg.data)
|
||||||
if msg.type == WSMsgType.BINARY:
|
if msg.type == WSMsgType.BINARY:
|
||||||
return await target.send_bytes(msg.data)
|
return await target.send_bytes(msg.data)
|
||||||
|
if msg.type == WSMsgType.CLOSE:
|
||||||
|
_LOGGER.debug("Received close message from WebSocket.")
|
||||||
|
return await target.close()
|
||||||
|
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"Cannot proxy websocket message of unsupported type: {msg.type}"
|
f"Cannot proxy websocket message of unsupported type: {msg.type}"
|
||||||
@ -200,6 +203,7 @@ class APIProxy(CoreSysAttributes):
|
|||||||
# init server
|
# init server
|
||||||
server = web.WebSocketResponse(heartbeat=30)
|
server = web.WebSocketResponse(heartbeat=30)
|
||||||
await server.prepare(request)
|
await server.prepare(request)
|
||||||
|
addon_name = None
|
||||||
|
|
||||||
# handle authentication
|
# handle authentication
|
||||||
try:
|
try:
|
||||||
@ -223,7 +227,8 @@ class APIProxy(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
return server
|
return server
|
||||||
|
|
||||||
_LOGGER.info("WebSocket access from %s", addon.slug)
|
addon_name = addon.slug
|
||||||
|
_LOGGER.info("WebSocket access from %s", addon_name)
|
||||||
|
|
||||||
await server.send_json(
|
await server.send_json(
|
||||||
{"type": "auth_ok", "ha_version": self.sys_homeassistant.version},
|
{"type": "auth_ok", "ha_version": self.sys_homeassistant.version},
|
||||||
@ -282,5 +287,5 @@ class APIProxy(CoreSysAttributes):
|
|||||||
if not server.closed:
|
if not server.closed:
|
||||||
await server.close()
|
await server.close()
|
||||||
|
|
||||||
_LOGGER.info("Home Assistant WebSocket API connection is closed")
|
_LOGGER.info("Home Assistant WebSocket API for %s closed", addon_name)
|
||||||
return server
|
return server
|
||||||
|
Loading…
x
Reference in New Issue
Block a user