Lazy loading of service descriptions (#11479)

* Lazy loading of service descriptions

* Fix tests

* Load YAML in executor

* Return a copy of available services to allow mutations

* Remove lint

* Add zha/services.yaml

* Only cache descriptions for known services

* Remove lint

* Remove description loading during service registration

* Remove description parameter from async_register

* Test async_get_all_descriptions

* Remove lint

* Fix typos from multi-edit

* Remove unused arguments

* Remove unused import os

* Remove unused import os, part 2

* Remove unneeded coroutine decorator

* Only use executor for loading files

* Cleanups suggested in review

* Increase test coverage

* Fix races in existing tests
This commit is contained in:
Anders Melchiorsen authored and Paulus Schoutsen committed 2018-01-07 14:54:16 -08:00
1 parent 3cbd77f6ac
commit 8267a21bfe
85 files changed
+253 -729

No files matched your search

@@ -7,12 +7,10 @@ https://home-assistant.io/components/image_processing/
import asyncio
from datetime import timedelta
import logging
import os
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.config import load_yaml_config_file
from homeassistant.const import (
ATTR_ENTITY_ID, CONF_NAME, CONF_ENTITY_ID)
from homeassistant.exceptions import HomeAssistantError
@@ -74,10 +72,6 @@ def async_setup(hass, config):
yield from component.async_setup(config)
descriptions = yield from hass.async_add_job(
load_yaml_config_file,
os.path.join(os.path.dirname(__file__), 'services.yaml'))
@asyncio.coroutine
def async_scan_service(service):
"""Service handler for scan."""
@@ -90,7 +84,7 @@ def async_setup(hass, config):
hass.services.async_register(
DOMAIN, SERVICE_SCAN, async_scan_service,
descriptions.get(SERVICE_SCAN), schema=SERVICE_SCAN_SCHEMA)
schema=SERVICE_SCAN_SCHEMA)
return True