add support for multiple execution per execute request (#10844)

This commit is contained in:
Per Osbäck 2017-11-29 08:16:29 +01:00 committed by Paulus Schoutsen
parent 99ea2c17a1
commit 253d5aea6e
2 changed files with 44 additions and 20 deletions

View File

@ -126,23 +126,23 @@ class GoogleAssistantView(HomeAssistantView):
commands = []
for command in requested_commands:
ent_ids = [ent.get('id') for ent in command.get('devices', [])]
execution = command.get('execution')[0]
for eid in ent_ids:
success = False
domain = eid.split('.')[0]
(service, service_data) = determine_service(
eid, execution.get('command'), execution.get('params'),
hass.config.units)
if domain == "group":
domain = "homeassistant"
success = yield from hass.services.async_call(
domain, service, service_data, blocking=True)
result = {"ids": [eid], "states": {}}
if success:
result['status'] = 'SUCCESS'
else:
result['status'] = 'ERROR'
commands.append(result)
for execution in command.get('execution'):
for eid in ent_ids:
success = False
domain = eid.split('.')[0]
(service, service_data) = determine_service(
eid, execution.get('command'), execution.get('params'),
hass.config.units)
if domain == "group":
domain = "homeassistant"
success = yield from hass.services.async_call(
domain, service, service_data, blocking=True)
result = {"ids": [eid], "states": {}}
if success:
result['status'] = 'SUCCESS'
else:
result['status'] = 'ERROR'
commands.append(result)
return self.json(
_make_actions_response(request_id, {'commands': commands}))

View File

@ -316,8 +316,6 @@ def test_execute_request(hass_fixture, assistant_client):
"id": "light.ceiling_lights",
}, {
"id": "switch.decorative_lights",
}, {
"id": "light.bed_light",
}],
"execution": [{
"command": "action.devices.commands.OnOff",
@ -350,6 +348,25 @@ def test_execute_request(hass_fixture, assistant_client):
}
}
}]
}, {
"devices": [{
"id": "light.bed_light"
}],
"execution": [{
"command": "action.devices.commands.ColorAbsolute",
"params": {
"color": {
"spectrumRGB": 65280
}
}
}, {
"command": "action.devices.commands.ColorAbsolute",
"params": {
"color": {
"temperature": 4700
}
}
}]
}]
}
}]
@ -362,10 +379,17 @@ def test_execute_request(hass_fixture, assistant_client):
body = yield from result.json()
assert body.get('requestId') == reqid
commands = body['payload']['commands']
assert len(commands) == 5
assert len(commands) == 6
ceiling = hass_fixture.states.get('light.ceiling_lights')
assert ceiling.state == 'off'
kitchen = hass_fixture.states.get('light.kitchen_lights')
assert kitchen.attributes.get(light.ATTR_COLOR_TEMP) == 476
assert kitchen.attributes.get(light.ATTR_RGB_COLOR) == (255, 0, 0)
bed = hass_fixture.states.get('light.bed_light')
assert bed.attributes.get(light.ATTR_COLOR_TEMP) == 212
assert bed.attributes.get(light.ATTR_RGB_COLOR) == (0, 255, 0)
assert hass_fixture.states.get('switch.decorative_lights').state == 'off'