mirror of
https://github.com/home-assistant/core.git
synced 2026-05-29 19:57:40 +01:00
d766aae436
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
36 lines
839 B
Python
36 lines
839 B
Python
"""Models for Recorder."""
|
|
|
|
from contextlib import suppress
|
|
from functools import lru_cache
|
|
import logging
|
|
from uuid import UUID
|
|
|
|
from homeassistant.util.ulid import ( # noqa: F401
|
|
bytes_to_ulid,
|
|
bytes_to_ulid_or_none,
|
|
ulid_to_bytes,
|
|
ulid_to_bytes_or_none,
|
|
)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
@lru_cache(maxsize=16)
|
|
def uuid_hex_to_bytes_or_none(uuid_hex: str | None) -> bytes | None:
|
|
"""Convert a uuid hex to bytes."""
|
|
if uuid_hex is None:
|
|
return None
|
|
with suppress(ValueError):
|
|
return UUID(hex=uuid_hex).bytes
|
|
return None
|
|
|
|
|
|
@lru_cache(maxsize=16)
|
|
def bytes_to_uuid_hex_or_none(_bytes: bytes | None) -> str | None:
|
|
"""Convert bytes to a uuid hex."""
|
|
if _bytes is None:
|
|
return None
|
|
with suppress(ValueError):
|
|
return UUID(bytes=_bytes).hex
|
|
return None
|