1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Avoid bytes to string to bytes conversion in websocket api (#108139)

This commit is contained in:
J. Nick Koston
2024-01-16 10:37:34 -10:00
committed by GitHub
parent ad35113e86
commit 60ab360fe7
16 changed files with 137 additions and 93 deletions

View File

@@ -29,7 +29,7 @@ from .deprecation import (
dir_with_deprecated_constants,
)
from .frame import report
from .json import JSON_DUMP, find_paths_unserializable_data
from .json import JSON_DUMP, find_paths_unserializable_data, json_bytes
from .typing import UNDEFINED, UndefinedType
if TYPE_CHECKING:
@@ -277,11 +277,11 @@ class DeviceEntry:
}
@cached_property
def json_repr(self) -> str | None:
def json_repr(self) -> bytes | None:
"""Return a cached JSON representation of the entry."""
try:
dict_repr = self.dict_repr
return JSON_DUMP(dict_repr)
return json_bytes(dict_repr)
except (ValueError, TypeError):
_LOGGER.error(
"Unable to serialize entry %s to JSON. Bad data found at %s",