Cloud: Websocket API to manage Google assistant entity config (#24153)

* Extract exposed devices function

* Add might_2fa info to trait

* Do not filter with should_expose in Google helper func

* Cloud: allow setting if Google entity is exposed

* Allow disabling 2FA via config

* Cloud: allow disabling 2FA

* Lint

* More changes

* Fix typing
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-05-29 08:39:12 -07:00
1 parent 85dfea1642
commit 6947f8cb2e
12 files changed
+346 -86

No files matched your search

+63 -3
View File
@@ -7,10 +7,13 @@ from jose import jwt
from hass_nabucasa.auth import Unauthenticated, UnknownError
from hass_nabucasa.const import STATE_CONNECTED
from homeassistant.core import State
from homeassistant.auth.providers import trusted_networks as tn_auth
from homeassistant.components.cloud.const import (
PREF_ENABLE_GOOGLE, PREF_ENABLE_ALEXA, PREF_GOOGLE_SECURE_DEVICES_PIN,
DOMAIN)
from homeassistant.components.google_assistant.helpers import (
GoogleEntity, Config)
from tests.common import mock_coro
@@ -32,7 +35,8 @@ def mock_cloud_login(hass, setup_api):
"""Mock cloud is logged in."""
hass.data[DOMAIN].id_token = jwt.encode({
'email': 'hello@home-assistant.io',
'custom:sub-exp': '2018-01-03'
'custom:sub-exp': '2018-01-03',
'cognito:username': 'abcdefghjkl',
}, 'test')
@@ -349,7 +353,15 @@ async def test_websocket_status(hass, hass_ws_client, mock_cloud_fixture,
'logged_in': True,
'email': 'hello@home-assistant.io',
'cloud': 'connected',
'prefs': mock_cloud_fixture,
'prefs': {
'alexa_enabled': True,
'cloud_user': None,
'cloudhooks': {},
'google_enabled': True,
'google_entity_configs': {},
'google_secure_devices_pin': None,
'remote_enabled': False,
},
'alexa_entities': {
'include_domains': [],
'include_entities': ['light.kitchen', 'switch.ac'],
@@ -363,7 +375,6 @@ async def test_websocket_status(hass, hass_ws_client, mock_cloud_fixture,
'exclude_domains': [],
'exclude_entities': [],
},
'google_domains': ['light'],
'remote_domain': None,
'remote_connected': False,
'remote_certificate': None,
@@ -689,3 +700,52 @@ async def test_enabling_remote_trusted_networks_other(
assert cloud.client.remote_autostart
assert len(mock_connect.mock_calls) == 1
async def test_list_google_entities(
hass, hass_ws_client, setup_api, mock_cloud_login):
"""Test that we can list Google entities."""
client = await hass_ws_client(hass)
entity = GoogleEntity(hass, Config(lambda *_: False), State(
'light.kitchen', 'on'
))
with patch('homeassistant.components.google_assistant.helpers'
'.async_get_entities', return_value=[entity]):
await client.send_json({
'id': 5,
'type': 'cloud/google_assistant/entities',
})
response = await client.receive_json()
assert response['success']
assert len(response['result']) == 1
assert response['result'][0] == {
'entity_id': 'light.kitchen',
'might_2fa': False,
'traits': ['action.devices.traits.OnOff'],
}
async def test_update_google_entity(
hass, hass_ws_client, setup_api, mock_cloud_login):
"""Test that we can update config of a Google entity."""
client = await hass_ws_client(hass)
await client.send_json({
'id': 5,
'type': 'cloud/google_assistant/entities/update',
'entity_id': 'light.kitchen',
'should_expose': False,
'override_name': 'updated name',
'aliases': ['lefty', 'righty'],
'disable_2fa': False,
})
response = await client.receive_json()
assert response['success']
prefs = hass.data[DOMAIN].client.prefs
assert prefs.google_entity_configs['light.kitchen'] == {
'should_expose': False,
'override_name': 'updated name',
'aliases': ['lefty', 'righty'],
'disable_2fa': False,
}