Google Assistant: make it possible to set a custom domain/type (#10188)
* Google Assistant: make it possible to set a custom domain/type * add test for switch platform * update custom type test
This commit is contained in:
parent
80a9539f97
commit
b6324b511c
5 changed files with 67 additions and 4 deletions
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
from homeassistant import setup, const, core
|
||||
from homeassistant.components import (
|
||||
http, async_setup, light, cover, media_player, fan
|
||||
http, async_setup, light, cover, media_player, fan, switch
|
||||
)
|
||||
from homeassistant.components import google_assistant as ga
|
||||
from tests.common import get_test_instance_port
|
||||
|
@ -62,6 +62,12 @@ def hass_fixture(loop, hass):
|
|||
'platform': 'demo'
|
||||
}]
|
||||
}))
|
||||
loop.run_until_complete(
|
||||
setup.async_setup_component(hass, switch.DOMAIN, {
|
||||
'switch': [{
|
||||
'platform': 'demo'
|
||||
}]
|
||||
}))
|
||||
loop.run_until_complete(
|
||||
setup.async_setup_component(hass, cover.DOMAIN, {
|
||||
'cover': [{
|
||||
|
@ -93,6 +99,16 @@ def hass_fixture(loop, hass):
|
|||
ceiling_lights_entity.state,
|
||||
attributes=attrs)
|
||||
|
||||
# By setting the google_assistant_type = 'light'
|
||||
# we can override how a device is reported to GA
|
||||
switch_light = hass.states.get('switch.decorative_lights')
|
||||
attrs = dict(switch_light.attributes)
|
||||
attrs[ga.const.ATTR_GOOGLE_ASSISTANT_TYPE] = "light"
|
||||
hass.states.async_set(
|
||||
switch_light.entity_id,
|
||||
switch_light.state,
|
||||
attributes=attrs)
|
||||
|
||||
return hass
|
||||
|
||||
|
||||
|
@ -188,6 +204,8 @@ def test_execute_request(hass_fixture, assistant_client):
|
|||
"commands": [{
|
||||
"devices": [{
|
||||
"id": "light.ceiling_lights",
|
||||
}, {
|
||||
"id": "switch.decorative_lights",
|
||||
}, {
|
||||
"id": "light.bed_light",
|
||||
}],
|
||||
|
@ -209,6 +227,7 @@ 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) == 2
|
||||
assert len(commands) == 3
|
||||
ceiling = hass_fixture.states.get('light.ceiling_lights')
|
||||
assert ceiling.state == 'off'
|
||||
assert hass_fixture.states.get('switch.decorative_lights').state == 'off'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue