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 2018-01-07 23:54:16 +01:00 committed by Paulus Schoutsen
parent 3cbd77f6ac
commit 8267a21bfe
85 changed files with 253 additions and 729 deletions

View file

@ -6,7 +6,6 @@ at https://home-assistant.io/components/input_boolean/
"""
import asyncio
import logging
import os
import voluptuous as vol
@ -15,7 +14,6 @@ from homeassistant.const import (
SERVICE_TOGGLE, STATE_ON)
from homeassistant.loader import bind_hass
import homeassistant.helpers.config_validation as cv
from homeassistant.config import load_yaml_config_file
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import async_get_last_state
@ -103,22 +101,14 @@ def async_setup(hass, config):
if tasks:
yield from asyncio.wait(tasks, loop=hass.loop)
descriptions = yield from hass.async_add_job(
load_yaml_config_file, os.path.join(
os.path.dirname(__file__), 'services.yaml')
)
hass.services.async_register(
DOMAIN, SERVICE_TURN_OFF, async_handler_service,
descriptions[DOMAIN][SERVICE_TURN_OFF],
schema=SERVICE_SCHEMA)
hass.services.async_register(
DOMAIN, SERVICE_TURN_ON, async_handler_service,
descriptions[DOMAIN][SERVICE_TURN_ON],
schema=SERVICE_SCHEMA)
hass.services.async_register(
DOMAIN, SERVICE_TOGGLE, async_handler_service,
descriptions[DOMAIN][SERVICE_TOGGLE],
schema=SERVICE_SCHEMA)
yield from component.async_add_entities(entities)