Skip to content
Snippets Groups Projects
Unverified Commit 0b3bcca4 authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

Avoid string decode/encode round trip in websocket_api get_services (#108632)

The cache was converting from bytes to str and when we read
the cache we converted it back to bytes again
parent a3f9fc45
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ from homeassistant.helpers.json import (
JSON_DUMP,
ExtendedJSONEncoder,
find_paths_unserializable_data,
json_dumps,
json_bytes,
)
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.helpers.typing import EventType
......@@ -460,7 +460,7 @@ def _send_handle_entities_init_response(
)
async def _async_get_all_descriptions_json(hass: HomeAssistant) -> str:
async def _async_get_all_descriptions_json(hass: HomeAssistant) -> bytes:
"""Return JSON of descriptions (i.e. user documentation) for all service calls."""
descriptions = await async_get_all_descriptions(hass)
if ALL_SERVICE_DESCRIPTIONS_JSON_CACHE in hass.data:
......@@ -469,8 +469,8 @@ async def _async_get_all_descriptions_json(hass: HomeAssistant) -> str:
]
# If the descriptions are the same, return the cached JSON payload
if cached_descriptions is descriptions:
return cast(str, cached_json_payload)
json_payload = json_dumps(descriptions)
return cast(bytes, cached_json_payload)
json_payload = json_bytes(descriptions)
hass.data[ALL_SERVICE_DESCRIPTIONS_JSON_CACHE] = (descriptions, json_payload)
return json_payload
......@@ -482,7 +482,7 @@ async def handle_get_services(
) -> None:
"""Handle get services command."""
payload = await _async_get_all_descriptions_json(hass)
connection.send_message(construct_result_message(msg["id"], payload.encode()))
connection.send_message(construct_result_message(msg["id"], payload))
@callback
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment