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:
parent
85dfea1642
commit
6947f8cb2e
12 changed files with 346 additions and 86 deletions
|
@ -2,9 +2,12 @@
|
|||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from aiohttp import web
|
||||
import jwt
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.cloud import DOMAIN
|
||||
from homeassistant.components.cloud.const import (
|
||||
PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE)
|
||||
from tests.components.alexa import test_smart_home as test_alexa
|
||||
|
@ -19,6 +22,25 @@ def mock_cloud():
|
|||
return MagicMock(subscription_expired=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_cloud_setup(hass):
|
||||
"""Set up the cloud."""
|
||||
with patch('hass_nabucasa.Cloud.start', return_value=mock_coro()):
|
||||
assert await async_setup_component(hass, 'cloud', {
|
||||
'cloud': {}
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_cloud_login(hass, mock_cloud_setup):
|
||||
"""Mock cloud is logged in."""
|
||||
hass.data[DOMAIN].id_token = jwt.encode({
|
||||
'email': 'hello@home-assistant.io',
|
||||
'custom:sub-exp': '2018-01-03',
|
||||
'cognito:username': 'abcdefghjkl',
|
||||
}, 'test')
|
||||
|
||||
|
||||
async def test_handler_alexa(hass):
|
||||
"""Test handler Alexa."""
|
||||
hass.states.async_set(
|
||||
|
@ -197,3 +219,35 @@ async def test_webhook_msg(hass):
|
|||
assert await received[0].json() == {
|
||||
'hello': 'world'
|
||||
}
|
||||
|
||||
|
||||
async def test_google_config_expose_entity(
|
||||
hass, mock_cloud_setup, mock_cloud_login):
|
||||
"""Test Google config exposing entity method uses latest config."""
|
||||
cloud_client = hass.data[DOMAIN].client
|
||||
state = State('light.kitchen', 'on')
|
||||
|
||||
assert cloud_client.google_config.should_expose(state)
|
||||
|
||||
await cloud_client.prefs.async_update_google_entity_config(
|
||||
entity_id='light.kitchen',
|
||||
should_expose=False,
|
||||
)
|
||||
|
||||
assert not cloud_client.google_config.should_expose(state)
|
||||
|
||||
|
||||
async def test_google_config_should_2fa(
|
||||
hass, mock_cloud_setup, mock_cloud_login):
|
||||
"""Test Google config disabling 2FA method uses latest config."""
|
||||
cloud_client = hass.data[DOMAIN].client
|
||||
state = State('light.kitchen', 'on')
|
||||
|
||||
assert cloud_client.google_config.should_2fa(state)
|
||||
|
||||
await cloud_client.prefs.async_update_google_entity_config(
|
||||
entity_id='light.kitchen',
|
||||
disable_2fa=True,
|
||||
)
|
||||
|
||||
assert not cloud_client.google_config.should_2fa(state)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue