mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Ensure load the device registry if it contains invalid configuration URLs (#97589)
This commit is contained in:
parent
33e5e3c5c2
commit
af5fc7e759
@ -198,9 +198,7 @@ class DeviceEntry:
|
|||||||
|
|
||||||
area_id: str | None = attr.ib(default=None)
|
area_id: str | None = attr.ib(default=None)
|
||||||
config_entries: set[str] = attr.ib(converter=set, factory=set)
|
config_entries: set[str] = attr.ib(converter=set, factory=set)
|
||||||
configuration_url: str | URL | None = attr.ib(
|
configuration_url: str | None = attr.ib(default=None)
|
||||||
converter=_validate_configuration_url, default=None
|
|
||||||
)
|
|
||||||
connections: set[tuple[str, str]] = attr.ib(converter=set, factory=set)
|
connections: set[tuple[str, str]] = attr.ib(converter=set, factory=set)
|
||||||
disabled_by: DeviceEntryDisabler | None = attr.ib(default=None)
|
disabled_by: DeviceEntryDisabler | None = attr.ib(default=None)
|
||||||
entry_type: DeviceEntryType | None = attr.ib(default=None)
|
entry_type: DeviceEntryType | None = attr.ib(default=None)
|
||||||
@ -482,6 +480,8 @@ class DeviceRegistry:
|
|||||||
via_device: tuple[str, str] | None | UndefinedType = UNDEFINED,
|
via_device: tuple[str, str] | None | UndefinedType = UNDEFINED,
|
||||||
) -> DeviceEntry:
|
) -> DeviceEntry:
|
||||||
"""Get device. Create if it doesn't exist."""
|
"""Get device. Create if it doesn't exist."""
|
||||||
|
if configuration_url is not UNDEFINED:
|
||||||
|
configuration_url = _validate_configuration_url(configuration_url)
|
||||||
|
|
||||||
# Reconstruct a DeviceInfo dict from the arguments.
|
# Reconstruct a DeviceInfo dict from the arguments.
|
||||||
# When we upgrade to Python 3.12, we can change this method to instead
|
# When we upgrade to Python 3.12, we can change this method to instead
|
||||||
@ -681,6 +681,9 @@ class DeviceRegistry:
|
|||||||
new_values["identifiers"] = new_identifiers
|
new_values["identifiers"] = new_identifiers
|
||||||
old_values["identifiers"] = old.identifiers
|
old_values["identifiers"] = old.identifiers
|
||||||
|
|
||||||
|
if configuration_url is not UNDEFINED:
|
||||||
|
configuration_url = _validate_configuration_url(configuration_url)
|
||||||
|
|
||||||
for attr_name, value in (
|
for attr_name, value in (
|
||||||
("area_id", area_id),
|
("area_id", area_id),
|
||||||
("configuration_url", configuration_url),
|
("configuration_url", configuration_url),
|
||||||
|
@ -1730,3 +1730,44 @@ async def test_device_info_configuration_url_validation(
|
|||||||
device_registry.async_update_device(
|
device_registry.async_update_device(
|
||||||
update_device.id, configuration_url=configuration_url
|
update_device.id, configuration_url=configuration_url
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("load_registries", [False])
|
||||||
|
async def test_loading_invalid_configuration_url_from_storage(
|
||||||
|
hass: HomeAssistant, hass_storage: dict[str, Any]
|
||||||
|
) -> None:
|
||||||
|
"""Test loading stored devices with an invalid URL."""
|
||||||
|
hass_storage[dr.STORAGE_KEY] = {
|
||||||
|
"version": dr.STORAGE_VERSION_MAJOR,
|
||||||
|
"minor_version": dr.STORAGE_VERSION_MINOR,
|
||||||
|
"data": {
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"area_id": None,
|
||||||
|
"config_entries": ["1234"],
|
||||||
|
"configuration_url": "invalid",
|
||||||
|
"connections": [],
|
||||||
|
"disabled_by": None,
|
||||||
|
"entry_type": dr.DeviceEntryType.SERVICE,
|
||||||
|
"hw_version": None,
|
||||||
|
"id": "abcdefghijklm",
|
||||||
|
"identifiers": [["serial", "12:34:56:AB:CD:EF"]],
|
||||||
|
"manufacturer": None,
|
||||||
|
"model": None,
|
||||||
|
"name_by_user": None,
|
||||||
|
"name": None,
|
||||||
|
"sw_version": None,
|
||||||
|
"via_device_id": None,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deleted_devices": [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await dr.async_load(hass)
|
||||||
|
registry = dr.async_get(hass)
|
||||||
|
assert len(registry.devices) == 1
|
||||||
|
entry = registry.async_get_or_create(
|
||||||
|
config_entry_id="1234", identifiers={("serial", "12:34:56:AB:CD:EF")}
|
||||||
|
)
|
||||||
|
assert entry.configuration_url == "invalid"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user