RFC: Call services directly (#18720)

* Call services directly

* Simplify

* Type

* Lint

* Update name

* Fix tests

* Catch exceptions in HTTP view

* Lint

* Handle ServiceNotFound in API endpoints that call services

* Type

* Don't crash recorder on non-JSON serializable objects
This commit is contained in:
Paulus Schoutsen 2018-11-30 21:28:35 +01:00 committed by Pascal Vizeli
parent 53cbb28926
commit df21dd21f2
30 changed files with 312 additions and 186 deletions

View file

@ -21,7 +21,7 @@ from homeassistant.const import (
__version__, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM,
ATTR_NOW, EVENT_TIME_CHANGED, EVENT_TIMER_OUT_OF_SYNC, ATTR_SECONDS,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_CLOSE,
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, EVENT_SERVICE_EXECUTED)
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED)
from tests.common import get_test_home_assistant, async_mock_service
@ -673,13 +673,8 @@ class TestServiceRegistry(unittest.TestCase):
def test_call_non_existing_with_blocking(self):
"""Test non-existing with blocking."""
prior = ha.SERVICE_CALL_LIMIT
try:
ha.SERVICE_CALL_LIMIT = 0.01
assert not self.services.call('test_domain', 'i_do_not_exist',
blocking=True)
finally:
ha.SERVICE_CALL_LIMIT = prior
with pytest.raises(ha.ServiceNotFound):
self.services.call('test_domain', 'i_do_not_exist', blocking=True)
def test_async_service(self):
"""Test registering and calling an async service."""
@ -1005,4 +1000,3 @@ async def test_service_executed_with_subservices(hass):
assert len(calls) == 4
assert [call.service for call in calls] == [
'outer', 'inner', 'inner', 'outer']
assert len(hass.bus.async_listeners().get(EVENT_SERVICE_EXECUTED, [])) == 0