Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions homeassistant/helpers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,29 @@ def domain_yaml_file(domain):
component_path = path.dirname(get_component(domain).__file__)
return path.join(component_path, 'services.yaml')

def load_services_file(yaml_file):
"""Load and cache a services.yaml file."""
try:
yaml_cache[yaml_file] = load_yaml(yaml_file)
except FileNotFoundError:
pass
def load_services_files(yaml_files):
"""Load and parse services.yaml files."""
loaded = {}
for yaml_file in yaml_files:
try:
loaded[yaml_file] = load_yaml(yaml_file)
except FileNotFoundError:
loaded[yaml_file] = {}

return loaded

services = hass.services.async_services()

# Load missing files
yaml_cache = {}
loading_tasks = []
missing = set()
for domain in services:
yaml_file = domain_yaml_file(domain)

for service in services[domain]:
if format_cache_key(domain, service) not in description_cache:
if yaml_file not in yaml_cache:
yaml_cache[yaml_file] = {}
task = hass.async_add_job(load_services_file, yaml_file)
loading_tasks.append(task)
missing.add(domain_yaml_file(domain))
break

if loading_tasks:
yield from asyncio.wait(loading_tasks, loop=hass.loop)
if missing:
loaded = yield from hass.async_add_job(load_services_files, missing)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to no longer use the YAML cache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cache needed descriptions in description_cache = hass.data[SERVICE_DESCRIPTION_CACHE] but the complete YAML file is discarded because it can contain many descriptions that we do not need.

That has not changed with this PR. However, apparently I got confused during the multiple reworks of the original PR and named yaml_cache poorly so now I renamed it.


# Build response
catch_all_yaml_file = domain_yaml_file(ha.DOMAIN)
Expand All @@ -176,9 +175,9 @@ def load_services_file(yaml_file):
# Cache missing descriptions
if description is None:
if yaml_file == catch_all_yaml_file:
yaml_services = yaml_cache[yaml_file].get(domain, {})
yaml_services = loaded[yaml_file].get(domain, {})
else:
yaml_services = yaml_cache[yaml_file]
yaml_services = loaded[yaml_file]
yaml_description = yaml_services.get(service, {})

description = description_cache[cache_key] = {
Expand Down