Use a dictcomp to reconstruct DeviceInfo in the device_registry (#117286)
Use a dictcomp to reconstruct DeviceInfo a dictcomp is faster than many sets on the dict by at least 25% We call this for nearly every device in the registry at startup
This commit is contained in:
parent
0acf392a50
commit
eac4aaef10
1 changed files with 21 additions and 21 deletions
|
@ -683,27 +683,27 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
||||||
# 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
|
||||||
# accept kwargs typed as a DeviceInfo dict (PEP 692)
|
# accept kwargs typed as a DeviceInfo dict (PEP 692)
|
||||||
device_info: DeviceInfo = {}
|
device_info: DeviceInfo = { # type: ignore[assignment]
|
||||||
for key, val in (
|
key: val
|
||||||
("configuration_url", configuration_url),
|
for key, val in (
|
||||||
("connections", connections),
|
("configuration_url", configuration_url),
|
||||||
("default_manufacturer", default_manufacturer),
|
("connections", connections),
|
||||||
("default_model", default_model),
|
("default_manufacturer", default_manufacturer),
|
||||||
("default_name", default_name),
|
("default_model", default_model),
|
||||||
("entry_type", entry_type),
|
("default_name", default_name),
|
||||||
("hw_version", hw_version),
|
("entry_type", entry_type),
|
||||||
("identifiers", identifiers),
|
("hw_version", hw_version),
|
||||||
("manufacturer", manufacturer),
|
("identifiers", identifiers),
|
||||||
("model", model),
|
("manufacturer", manufacturer),
|
||||||
("name", name),
|
("model", model),
|
||||||
("serial_number", serial_number),
|
("name", name),
|
||||||
("suggested_area", suggested_area),
|
("serial_number", serial_number),
|
||||||
("sw_version", sw_version),
|
("suggested_area", suggested_area),
|
||||||
("via_device", via_device),
|
("sw_version", sw_version),
|
||||||
):
|
("via_device", via_device),
|
||||||
if val is UNDEFINED:
|
)
|
||||||
continue
|
if val is not UNDEFINED
|
||||||
device_info[key] = val # type: ignore[literal-required]
|
}
|
||||||
|
|
||||||
device_info_type = _validate_device_info(config_entry, device_info)
|
device_info_type = _validate_device_info(config_entry, device_info)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue