Add context to service call event (#21181)
This commit is contained in:
parent
463c4ae5c9
commit
d2fea76fd7
2 changed files with 9 additions and 3 deletions
|
@ -1117,7 +1117,7 @@ class ServiceRegistry:
|
||||||
ATTR_DOMAIN: domain.lower(),
|
ATTR_DOMAIN: domain.lower(),
|
||||||
ATTR_SERVICE: service.lower(),
|
ATTR_SERVICE: service.lower(),
|
||||||
ATTR_SERVICE_DATA: service_data,
|
ATTR_SERVICE_DATA: service_data,
|
||||||
})
|
}, context=context)
|
||||||
|
|
||||||
if not blocking:
|
if not blocking:
|
||||||
self._hass.async_create_task(
|
self._hass.async_create_task(
|
||||||
|
|
|
@ -1013,6 +1013,7 @@ def test_track_task_functions(loop):
|
||||||
async def test_service_executed_with_subservices(hass):
|
async def test_service_executed_with_subservices(hass):
|
||||||
"""Test we block correctly till all services done."""
|
"""Test we block correctly till all services done."""
|
||||||
calls = async_mock_service(hass, 'test', 'inner')
|
calls = async_mock_service(hass, 'test', 'inner')
|
||||||
|
context = ha.Context()
|
||||||
|
|
||||||
async def handle_outer(call):
|
async def handle_outer(call):
|
||||||
"""Handle outer service call."""
|
"""Handle outer service call."""
|
||||||
|
@ -1026,11 +1027,13 @@ async def test_service_executed_with_subservices(hass):
|
||||||
|
|
||||||
hass.services.async_register('test', 'outer', handle_outer)
|
hass.services.async_register('test', 'outer', handle_outer)
|
||||||
|
|
||||||
await hass.services.async_call('test', 'outer', blocking=True)
|
await hass.services.async_call('test', 'outer', blocking=True,
|
||||||
|
context=context)
|
||||||
|
|
||||||
assert len(calls) == 4
|
assert len(calls) == 4
|
||||||
assert [call.service for call in calls] == [
|
assert [call.service for call in calls] == [
|
||||||
'outer', 'inner', 'inner', 'outer']
|
'outer', 'inner', 'inner', 'outer']
|
||||||
|
assert all(call.context is context for call in calls)
|
||||||
|
|
||||||
|
|
||||||
async def test_service_call_event_contains_original_data(hass):
|
async def test_service_call_event_contains_original_data(hass):
|
||||||
|
@ -1047,11 +1050,14 @@ async def test_service_call_event_contains_original_data(hass):
|
||||||
'number': vol.Coerce(int)
|
'number': vol.Coerce(int)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
context = ha.Context()
|
||||||
await hass.services.async_call('test', 'service', {
|
await hass.services.async_call('test', 'service', {
|
||||||
'number': '23'
|
'number': '23'
|
||||||
}, blocking=True)
|
}, blocking=True, context=context)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
assert events[0].data['service_data']['number'] == '23'
|
assert events[0].data['service_data']['number'] == '23'
|
||||||
|
assert events[0].context is context
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data['number'] == 23
|
assert calls[0].data['number'] == 23
|
||||||
|
assert calls[0].context is context
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue