Allow configuration_url to be removed/nullified from device registry (#58564)
* Allow configuration_url to be removed from device registry * Add test * Check for None before stringifying and url parsing * Add type to dict to remove mypy error on assigning None
This commit is contained in:
parent
6a3c23d02a
commit
ea028e38d5
2 changed files with 62 additions and 12 deletions
|
@ -458,7 +458,9 @@ class EntityPlatform:
|
|||
device_id = None
|
||||
|
||||
if config_entry_id is not None and device_info is not None:
|
||||
processed_dev_info = {"config_entry_id": config_entry_id}
|
||||
processed_dev_info: dict[str, str | None] = {
|
||||
"config_entry_id": config_entry_id
|
||||
}
|
||||
for key in (
|
||||
"connections",
|
||||
"default_manufacturer",
|
||||
|
@ -477,18 +479,21 @@ class EntityPlatform:
|
|||
processed_dev_info[key] = device_info[key] # type: ignore[misc]
|
||||
|
||||
if "configuration_url" in device_info:
|
||||
configuration_url = str(device_info["configuration_url"])
|
||||
if urlparse(configuration_url).scheme in [
|
||||
"http",
|
||||
"https",
|
||||
"homeassistant",
|
||||
]:
|
||||
processed_dev_info["configuration_url"] = configuration_url
|
||||
if device_info["configuration_url"] is None:
|
||||
processed_dev_info["configuration_url"] = None
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Ignoring invalid device configuration_url '%s'",
|
||||
configuration_url,
|
||||
)
|
||||
configuration_url = str(device_info["configuration_url"])
|
||||
if urlparse(configuration_url).scheme in [
|
||||
"http",
|
||||
"https",
|
||||
"homeassistant",
|
||||
]:
|
||||
processed_dev_info["configuration_url"] = configuration_url
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Ignoring invalid device configuration_url '%s'",
|
||||
configuration_url,
|
||||
)
|
||||
|
||||
try:
|
||||
device = device_registry.async_get_or_create(**processed_dev_info) # type: ignore[arg-type]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue