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:
parent
3cbd77f6ac
commit
8267a21bfe
85 changed files with 253 additions and 729 deletions
|
@ -21,6 +21,7 @@ from homeassistant.components import frontend
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.remote import JSONEncoder
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.service import async_get_all_descriptions
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.http.auth import validate_password
|
||||
from homeassistant.components.http.const import KEY_AUTHENTICATED
|
||||
|
@ -436,7 +437,7 @@ class ActiveConnection:
|
|||
def handle_call_service(self, msg):
|
||||
"""Handle call service command.
|
||||
|
||||
This is a coroutine.
|
||||
Async friendly.
|
||||
"""
|
||||
msg = CALL_SERVICE_MESSAGE_SCHEMA(msg)
|
||||
|
||||
|
@ -466,8 +467,13 @@ class ActiveConnection:
|
|||
"""
|
||||
msg = GET_SERVICES_MESSAGE_SCHEMA(msg)
|
||||
|
||||
self.to_write.put_nowait(result_message(
|
||||
msg['id'], self.hass.services.async_services()))
|
||||
@asyncio.coroutine
|
||||
def get_services_helper(msg):
|
||||
"""Get available services and fire complete message."""
|
||||
descriptions = yield from async_get_all_descriptions(self.hass)
|
||||
self.send_message_outside(result_message(msg['id'], descriptions))
|
||||
|
||||
self.hass.async_add_job(get_services_helper(msg))
|
||||
|
||||
def handle_get_config(self, msg):
|
||||
"""Handle get config command.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue