1 """Helper to create a unique instance ID."""
3 from __future__
import annotations
10 from .
import singleton, storage
12 DATA_KEY =
"core.uuid"
15 LEGACY_UUID_FILE =
".uuid"
17 _LOGGER = logging.getLogger(__name__)
20 @singleton.singleton(DATA_KEY)
22 """Get unique ID for the hass instance."""
23 store =
storage.Store[dict[str, str]](hass, DATA_VERSION, DATA_KEY,
True)
25 data: dict[str, str] |
None =
None
27 data = await storage.async_migrator(
29 hass.config.path(LEGACY_UUID_FILE),
35 "Could not read hass instance ID from '%s' or '%s', a new instance ID "
45 data = {
"uuid": uuid.uuid4().hex}
47 await store.async_save(data)
str async_get(HomeAssistant hass)