Re-thrown exception occurred in the blocking service call (#21573)

* Rethrown exception occurred in the actual service call

* Fix lint and test
This commit is contained in:
Jason Hu authored and Paulus Schoutsen committed 2019-03-04 15:59:14 -08:00
1 parent 996e0a6389
commit a268aab2ec
6 files changed
+114 -8

No files matched your search

@@ -3,7 +3,8 @@ import voluptuous as vol
from homeassistant.const import MATCH_ALL, EVENT_TIME_CHANGED
from homeassistant.core import callback, DOMAIN as HASS_DOMAIN
from homeassistant.exceptions import Unauthorized, ServiceNotFound
from homeassistant.exceptions import Unauthorized, ServiceNotFound, \
HomeAssistantError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.service import async_get_all_descriptions
@@ -149,6 +150,12 @@ async def handle_call_service(hass, connection, msg):
except ServiceNotFound:
connection.send_message(messages.error_message(
msg['id'], const.ERR_NOT_FOUND, 'Service not found.'))
except HomeAssistantError as err:
connection.send_message(messages.error_message(
msg['id'], const.ERR_HOME_ASSISTANT_ERROR, '{}'.format(err)))
except Exception as err: # pylint: disable=broad-except
connection.send_message(messages.error_message(
msg['id'], const.ERR_UNKNOWN_ERROR, '{}'.format(err)))
@callback
@@ -9,6 +9,7 @@ MAX_PENDING_MSG = 512
ERR_ID_REUSE = 'id_reuse'
ERR_INVALID_FORMAT = 'invalid_format'
ERR_NOT_FOUND = 'not_found'
ERR_HOME_ASSISTANT_ERROR = 'home_assistant_error'
ERR_UNKNOWN_COMMAND = 'unknown_command'
ERR_UNKNOWN_ERROR = 'unknown_error'
ERR_UNAUTHORIZED = 'unauthorized'
+8 -2
View File
@@ -272,7 +272,10 @@ async def entity_service_call(hass, platforms, func, call, service_name=''):
]
if tasks:
await asyncio.wait(tasks)
done, pending = await asyncio.wait(tasks)
assert not pending
for future in done:
future.result() # pop exception if have
async def _handle_service_platform_call(func, data, entities, context):
@@ -294,4 +297,7 @@ async def _handle_service_platform_call(func, data, entities, context):
tasks.append(entity.async_update_ha_state(True))
if tasks:
await asyncio.wait(tasks)
done, pending = await asyncio.wait(tasks)
assert not pending
for future in done:
future.result() # pop exception if have