Add target to service call API (#45898)

* Add target to service call API

* Fix _async_call_service_step

* CONF_SERVICE_ENTITY_ID overrules target

* Move merging up before processing schema

* Restore services.yaml

* Add test
This commit is contained in:
Bram Kragten 2021-02-10 12:42:28 +01:00 committed by GitHub
parent 7d2d98fc3c
commit 4b493c5ab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 16 deletions

View file

@ -52,6 +52,47 @@ async def test_call_service(hass, websocket_client):
assert call.data == {"hello": "world"}
async def test_call_service_target(hass, websocket_client):
"""Test call service command with target."""
calls = []
@callback
def service_call(call):
calls.append(call)
hass.services.async_register("domain_test", "test_service", service_call)
await websocket_client.send_json(
{
"id": 5,
"type": "call_service",
"domain": "domain_test",
"service": "test_service",
"service_data": {"hello": "world"},
"target": {
"entity_id": ["entity.one", "entity.two"],
"device_id": "deviceid",
},
}
)
msg = await websocket_client.receive_json()
assert msg["id"] == 5
assert msg["type"] == const.TYPE_RESULT
assert msg["success"]
assert len(calls) == 1
call = calls[0]
assert call.domain == "domain_test"
assert call.service == "test_service"
assert call.data == {
"hello": "world",
"entity_id": ["entity.one", "entity.two"],
"device_id": ["deviceid"],
}
async def test_call_service_not_found(hass, websocket_client):
"""Test call service command."""
await websocket_client.send_json(