mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Simplify service description cache logic (#117846)
This commit is contained in:
parent
e8fc4e0f19
commit
905692901c
@ -669,15 +669,11 @@ async def async_get_all_descriptions(
|
|||||||
|
|
||||||
# See if there are new services not seen before.
|
# See if there are new services not seen before.
|
||||||
# Any service that we saw before already has an entry in description_cache.
|
# Any service that we saw before already has an entry in description_cache.
|
||||||
domains_with_missing_services: set[str] = set()
|
all_services = {
|
||||||
all_services: set[tuple[str, str]] = set()
|
(domain, service_name)
|
||||||
for domain, services_by_domain in services.items():
|
for domain, services_by_domain in services.items()
|
||||||
for service_name in services_by_domain:
|
for service_name in services_by_domain
|
||||||
cache_key = (domain, service_name)
|
}
|
||||||
all_services.add(cache_key)
|
|
||||||
if cache_key not in descriptions_cache:
|
|
||||||
domains_with_missing_services.add(domain)
|
|
||||||
|
|
||||||
# If we have a complete cache, check if it is still valid
|
# If we have a complete cache, check if it is still valid
|
||||||
all_cache: tuple[set[tuple[str, str]], dict[str, dict[str, Any]]] | None
|
all_cache: tuple[set[tuple[str, str]], dict[str, dict[str, Any]]] | None
|
||||||
if all_cache := hass.data.get(ALL_SERVICE_DESCRIPTIONS_CACHE):
|
if all_cache := hass.data.get(ALL_SERVICE_DESCRIPTIONS_CACHE):
|
||||||
@ -694,7 +690,9 @@ async def async_get_all_descriptions(
|
|||||||
# add the new ones to the cache without their descriptions
|
# add the new ones to the cache without their descriptions
|
||||||
services = {domain: service.copy() for domain, service in services.items()}
|
services = {domain: service.copy() for domain, service in services.items()}
|
||||||
|
|
||||||
if domains_with_missing_services:
|
if domains_with_missing_services := {
|
||||||
|
domain for domain, _ in all_services.difference(descriptions_cache)
|
||||||
|
}:
|
||||||
ints_or_excs = await async_get_integrations(hass, domains_with_missing_services)
|
ints_or_excs = await async_get_integrations(hass, domains_with_missing_services)
|
||||||
integrations: list[Integration] = []
|
integrations: list[Integration] = []
|
||||||
for domain, int_or_exc in ints_or_excs.items():
|
for domain, int_or_exc in ints_or_excs.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user