Provide slight speedup to Guardian device lookup during service call (#77004)

* Provide slight speedup to Guardian device lookup during service call

* Messages
This commit is contained in:
Aaron Bach 2022-08-19 01:39:48 -06:00 committed by GitHub
parent 6d49362573
commit dd109839b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,12 +103,16 @@ def async_get_entry_id_for_service_call(hass: HomeAssistant, call: ServiceCall)
device_id = call.data[CONF_DEVICE_ID]
device_registry = dr.async_get(hass)
if device_entry := device_registry.async_get(device_id):
for entry in hass.config_entries.async_entries(DOMAIN):
if entry.entry_id in device_entry.config_entries:
return entry.entry_id
if (device_entry := device_registry.async_get(device_id)) is None:
raise ValueError(f"Invalid Guardian device ID: {device_id}")
raise ValueError(f"No client for device ID: {device_id}")
for entry_id in device_entry.config_entries:
if (entry := hass.config_entries.async_get_entry(entry_id)) is None:
continue
if entry.domain == DOMAIN:
return entry_id
raise ValueError(f"No config entry for device ID: {device_id}")
@callback