mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
add support for multiple execution per execute request (#10844)
This commit is contained in:
parent
99ea2c17a1
commit
253d5aea6e
@ -126,23 +126,23 @@ class GoogleAssistantView(HomeAssistantView):
|
|||||||
commands = []
|
commands = []
|
||||||
for command in requested_commands:
|
for command in requested_commands:
|
||||||
ent_ids = [ent.get('id') for ent in command.get('devices', [])]
|
ent_ids = [ent.get('id') for ent in command.get('devices', [])]
|
||||||
execution = command.get('execution')[0]
|
for execution in command.get('execution'):
|
||||||
for eid in ent_ids:
|
for eid in ent_ids:
|
||||||
success = False
|
success = False
|
||||||
domain = eid.split('.')[0]
|
domain = eid.split('.')[0]
|
||||||
(service, service_data) = determine_service(
|
(service, service_data) = determine_service(
|
||||||
eid, execution.get('command'), execution.get('params'),
|
eid, execution.get('command'), execution.get('params'),
|
||||||
hass.config.units)
|
hass.config.units)
|
||||||
if domain == "group":
|
if domain == "group":
|
||||||
domain = "homeassistant"
|
domain = "homeassistant"
|
||||||
success = yield from hass.services.async_call(
|
success = yield from hass.services.async_call(
|
||||||
domain, service, service_data, blocking=True)
|
domain, service, service_data, blocking=True)
|
||||||
result = {"ids": [eid], "states": {}}
|
result = {"ids": [eid], "states": {}}
|
||||||
if success:
|
if success:
|
||||||
result['status'] = 'SUCCESS'
|
result['status'] = 'SUCCESS'
|
||||||
else:
|
else:
|
||||||
result['status'] = 'ERROR'
|
result['status'] = 'ERROR'
|
||||||
commands.append(result)
|
commands.append(result)
|
||||||
|
|
||||||
return self.json(
|
return self.json(
|
||||||
_make_actions_response(request_id, {'commands': commands}))
|
_make_actions_response(request_id, {'commands': commands}))
|
||||||
|
@ -316,8 +316,6 @@ def test_execute_request(hass_fixture, assistant_client):
|
|||||||
"id": "light.ceiling_lights",
|
"id": "light.ceiling_lights",
|
||||||
}, {
|
}, {
|
||||||
"id": "switch.decorative_lights",
|
"id": "switch.decorative_lights",
|
||||||
}, {
|
|
||||||
"id": "light.bed_light",
|
|
||||||
}],
|
}],
|
||||||
"execution": [{
|
"execution": [{
|
||||||
"command": "action.devices.commands.OnOff",
|
"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()
|
body = yield from result.json()
|
||||||
assert body.get('requestId') == reqid
|
assert body.get('requestId') == reqid
|
||||||
commands = body['payload']['commands']
|
commands = body['payload']['commands']
|
||||||
assert len(commands) == 5
|
assert len(commands) == 6
|
||||||
|
|
||||||
ceiling = hass_fixture.states.get('light.ceiling_lights')
|
ceiling = hass_fixture.states.get('light.ceiling_lights')
|
||||||
assert ceiling.state == 'off'
|
assert ceiling.state == 'off'
|
||||||
|
|
||||||
kitchen = hass_fixture.states.get('light.kitchen_lights')
|
kitchen = hass_fixture.states.get('light.kitchen_lights')
|
||||||
assert kitchen.attributes.get(light.ATTR_COLOR_TEMP) == 476
|
assert kitchen.attributes.get(light.ATTR_COLOR_TEMP) == 476
|
||||||
assert kitchen.attributes.get(light.ATTR_RGB_COLOR) == (255, 0, 0)
|
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'
|
assert hass_fixture.states.get('switch.decorative_lights').state == 'off'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user