mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-25 18:16:32 +00:00
Use orjson encoder for websocket messages (#4854)
I missed that these need to have dumps passed
This commit is contained in:
parent
140b769a42
commit
375789b019
@ -14,6 +14,7 @@ from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
|
||||
|
||||
from ..coresys import CoreSysAttributes
|
||||
from ..exceptions import APIError, HomeAssistantAPIError, HomeAssistantAuthError
|
||||
from ..utils.json import json_dumps
|
||||
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
@ -145,7 +146,8 @@ class APIProxy(CoreSysAttributes):
|
||||
{
|
||||
"type": "auth",
|
||||
"access_token": self.sys_homeassistant.api.access_token,
|
||||
}
|
||||
},
|
||||
dumps=json_dumps,
|
||||
)
|
||||
|
||||
data = await client.receive_json()
|
||||
@ -202,7 +204,8 @@ class APIProxy(CoreSysAttributes):
|
||||
# handle authentication
|
||||
try:
|
||||
await server.send_json(
|
||||
{"type": "auth_required", "ha_version": self.sys_homeassistant.version}
|
||||
{"type": "auth_required", "ha_version": self.sys_homeassistant.version},
|
||||
dumps=json_dumps,
|
||||
)
|
||||
|
||||
# Check API access
|
||||
@ -215,14 +218,16 @@ class APIProxy(CoreSysAttributes):
|
||||
if not addon or not addon.access_homeassistant_api:
|
||||
_LOGGER.warning("Unauthorized WebSocket access!")
|
||||
await server.send_json(
|
||||
{"type": "auth_invalid", "message": "Invalid access"}
|
||||
{"type": "auth_invalid", "message": "Invalid access"},
|
||||
dumps=json_dumps,
|
||||
)
|
||||
return server
|
||||
|
||||
_LOGGER.info("WebSocket access from %s", addon.slug)
|
||||
|
||||
await server.send_json(
|
||||
{"type": "auth_ok", "ha_version": self.sys_homeassistant.version}
|
||||
{"type": "auth_ok", "ha_version": self.sys_homeassistant.version},
|
||||
dumps=json_dumps,
|
||||
)
|
||||
except (RuntimeError, ValueError) as err:
|
||||
_LOGGER.error("Can't initialize handshake: %s", err)
|
||||
|
@ -26,6 +26,7 @@ from ..exceptions import (
|
||||
HomeAssistantWSError,
|
||||
HomeAssistantWSNotSupported,
|
||||
)
|
||||
from ..utils.json import json_dumps
|
||||
from .const import CLOSING_STATES, WSEvent, WSType
|
||||
|
||||
MIN_VERSION = {
|
||||
@ -74,7 +75,7 @@ class WSClient:
|
||||
self._message_id += 1
|
||||
_LOGGER.debug("Sending: %s", message)
|
||||
try:
|
||||
await self._client.send_json(message)
|
||||
await self._client.send_json(message, dumps=json_dumps)
|
||||
except ConnectionError as err:
|
||||
raise HomeAssistantWSConnectionError(err) from err
|
||||
|
||||
@ -85,7 +86,7 @@ class WSClient:
|
||||
self._futures[message["id"]] = self._loop.create_future()
|
||||
_LOGGER.debug("Sending: %s", message)
|
||||
try:
|
||||
await self._client.send_json(message)
|
||||
await self._client.send_json(message, dumps=json_dumps)
|
||||
except ConnectionError as err:
|
||||
raise HomeAssistantWSConnectionError(err) from err
|
||||
|
||||
@ -163,7 +164,9 @@ class WSClient:
|
||||
|
||||
hello_message = await client.receive_json()
|
||||
|
||||
await client.send_json({ATTR_TYPE: WSType.AUTH, ATTR_ACCESS_TOKEN: token})
|
||||
await client.send_json(
|
||||
{ATTR_TYPE: WSType.AUTH, ATTR_ACCESS_TOKEN: token}, dumps=json_dumps
|
||||
)
|
||||
|
||||
auth_ok_message = await client.receive_json()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user