Don't use executor in send_big_result (#75427)

pull/75448/head
uvjustin 2022-07-19 21:40:23 +08:00 committed by GitHub
parent b6d235c0c2
commit 6b60fb9541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 10 deletions

View File

@ -804,7 +804,7 @@ async def websocket_camera_thumbnail(
_LOGGER.warning("The websocket command 'camera_thumbnail' has been deprecated")
try:
image = await async_get_image(hass, msg["entity_id"])
await connection.send_big_result(
connection.send_big_result(
msg["id"],
{
"content_type": image.content_type,

View File

@ -38,7 +38,7 @@ def _handle_errors(func):
return
if msg is not None:
await connection.send_big_result(msg["id"], result)
connection.send_big_result(msg["id"], result)
else:
connection.send_result(msg["id"], result)

View File

@ -1164,7 +1164,7 @@ async def websocket_handle_thumbnail(hass, connection, msg):
)
return
await connection.send_big_result(
connection.send_big_result(
msg["id"],
{
"content_type": content_type,

View File

@ -54,12 +54,9 @@ class ActiveConnection:
"""Send a result message."""
self.send_message(messages.result_message(msg_id, result))
async def send_big_result(self, msg_id: int, result: Any) -> None:
def send_big_result(self, msg_id: int, result: Any) -> None:
"""Send a result message that would be expensive to JSON serialize."""
content = await self.hass.async_add_executor_job(
JSON_DUMP, messages.result_message(msg_id, result)
)
self.send_message(content)
self.send_message(JSON_DUMP(messages.result_message(msg_id, result)))
@callback
def send_error(self, msg_id: int, code: str, message: str) -> None:

View File

@ -17,8 +17,8 @@ async def test_send_big_result(hass, websocket_client):
@websocket_api.websocket_command({"type": "big_result"})
@websocket_api.async_response
async def send_big_result(hass, connection, msg):
await connection.send_big_result(msg["id"], {"big": "result"})
def send_big_result(hass, connection, msg):
connection.send_big_result(msg["id"], {"big": "result"})
websocket_api.async_register_command(hass, send_big_result)