Optimize mqtt device cleanup (#111170)

Thnx
This commit is contained in:
Jan Bouwhuis 2024-02-23 07:29:50 +01:00 committed by GitHub
parent 8d4569ff55
commit afa4e76248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1347,15 +1347,12 @@ def async_removed_from_device(
config_entry_id: str,
) -> bool:
"""Check if the passed event indicates MQTT was removed from a device."""
if event.data["action"] not in ("remove", "update"):
return False
if event.data["action"] == "update":
if "config_entries" not in event.data["changes"]:
return False
device_registry = dr.async_get(hass)
if (
device_entry := device_registry.async_get(event.data["device_id"])
device_entry := device_registry.async_get(mqtt_device_id)
) and config_entry_id in device_entry.config_entries:
# Not removed from device
return False