Use ULID instead of UUID for config entry id and flow ID (#118677)

pull/118706/head
Erik Montnemery 2024-06-03 10:34:09 +02:00 committed by GitHub
parent 6cf7889c38
commit 35dcda29b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -66,7 +66,7 @@ from .setup import (
async_setup_component,
async_start_setup,
)
from .util import uuid as uuid_util
from .util import ulid as ulid_util
from .util.async_ import create_eager_task
from .util.decorator import Registry
from .util.enum import try_parse_enum
@ -324,7 +324,7 @@ class ConfigEntry(Generic[_DataT]):
"""Initialize a config entry."""
_setter = object.__setattr__
# Unique id of the config entry
_setter(self, "entry_id", entry_id or uuid_util.random_uuid_hex())
_setter(self, "entry_id", entry_id or ulid_util.ulid_now())
# Version of the configuration.
_setter(self, "version", version)
@ -1226,7 +1226,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]):
if not context or "source" not in context:
raise KeyError("Context not set or doesn't have a source set")
flow_id = uuid_util.random_uuid_hex()
flow_id = ulid_util.ulid_now()
# Avoid starting a config flow on an integration that only supports
# a single config entry, but which already has an entry

View File

@ -95,8 +95,8 @@ from homeassistant.util.json import (
json_loads_object,
)
from homeassistant.util.signal_type import SignalType
import homeassistant.util.ulid as ulid_util
from homeassistant.util.unit_system import METRIC_SYSTEM
import homeassistant.util.uuid as uuid_util
import homeassistant.util.yaml.loader as yaml_loader
from tests.testing_config.custom_components.test_constant_deprecation import (
@ -999,7 +999,7 @@ class MockConfigEntry(config_entries.ConfigEntry[_DataT]):
"data": data or {},
"disabled_by": disabled_by,
"domain": domain,
"entry_id": entry_id or uuid_util.random_uuid_hex(),
"entry_id": entry_id or ulid_util.ulid_now(),
"minor_version": minor_version,
"options": options or {},
"pref_disable_new_entities": pref_disable_new_entities,

View File

@ -2329,7 +2329,7 @@ async def test_entry_id_existing_entry(
pytest.raises(HomeAssistantError),
patch.dict(config_entries.HANDLERS, {"comp": TestFlow}),
patch(
"homeassistant.config_entries.uuid_util.random_uuid_hex",
"homeassistant.config_entries.ulid_util.ulid_now",
return_value=collide_entry_id,
),
):