mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
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
This commit is contained in:
parent
a3f9fc45e3
commit
0b3bcca49b
@ -45,7 +45,7 @@ from homeassistant.helpers.json import (
|
|||||||
JSON_DUMP,
|
JSON_DUMP,
|
||||||
ExtendedJSONEncoder,
|
ExtendedJSONEncoder,
|
||||||
find_paths_unserializable_data,
|
find_paths_unserializable_data,
|
||||||
json_dumps,
|
json_bytes,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.service import async_get_all_descriptions
|
from homeassistant.helpers.service import async_get_all_descriptions
|
||||||
from homeassistant.helpers.typing import EventType
|
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."""
|
"""Return JSON of descriptions (i.e. user documentation) for all service calls."""
|
||||||
descriptions = await async_get_all_descriptions(hass)
|
descriptions = await async_get_all_descriptions(hass)
|
||||||
if ALL_SERVICE_DESCRIPTIONS_JSON_CACHE in hass.data:
|
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 the descriptions are the same, return the cached JSON payload
|
||||||
if cached_descriptions is descriptions:
|
if cached_descriptions is descriptions:
|
||||||
return cast(str, cached_json_payload)
|
return cast(bytes, cached_json_payload)
|
||||||
json_payload = json_dumps(descriptions)
|
json_payload = json_bytes(descriptions)
|
||||||
hass.data[ALL_SERVICE_DESCRIPTIONS_JSON_CACHE] = (descriptions, json_payload)
|
hass.data[ALL_SERVICE_DESCRIPTIONS_JSON_CACHE] = (descriptions, json_payload)
|
||||||
return json_payload
|
return json_payload
|
||||||
|
|
||||||
@ -482,7 +482,7 @@ async def handle_get_services(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Handle get services command."""
|
"""Handle get services command."""
|
||||||
payload = await _async_get_all_descriptions_json(hass)
|
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
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user