Refactor handling of exposed entities for cloud Alexa and Google (#89877)
* Refactor handling of exposed entities for cloud Alexa * Tweak WS API * Validate assistant parameter * Address some review comments * Refactor handling of exposed entities for cloud Google * Raise when attempting to expose an unknown entity * Add tests * Adjust cloud tests * Allow getting expose new entities flag * Test Alexa migration * Test Google migration * Add WS command cloud/google_assistant/entities/get * Fix return value * Update typing * Address review comments * Rename async_get_exposed_entities to async_get_assistant_settings
This commit is contained in:
parent
0d84106947
commit
44c89a6b6c
17 changed files with 1607 additions and 305 deletions
|
@ -13,8 +13,13 @@ from homeassistant.components.cloud.const import (
|
|||
PREF_ENABLE_ALEXA,
|
||||
PREF_ENABLE_GOOGLE,
|
||||
)
|
||||
from homeassistant.components.homeassistant.exposed_entities import (
|
||||
DATA_EXPOSED_ENTITIES,
|
||||
ExposedEntities,
|
||||
)
|
||||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
|
@ -245,14 +250,25 @@ async def test_google_config_expose_entity(
|
|||
hass: HomeAssistant, mock_cloud_setup, mock_cloud_login
|
||||
) -> None:
|
||||
"""Test Google config exposing entity method uses latest config."""
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
# Enable exposing new entities to Google
|
||||
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
|
||||
exposed_entities.async_set_expose_new_entities("cloud.google_assistant", True)
|
||||
|
||||
# Register a light entity
|
||||
entity_entry = entity_registry.async_get_or_create(
|
||||
"light", "test", "unique", suggested_object_id="kitchen"
|
||||
)
|
||||
|
||||
cloud_client = hass.data[DOMAIN].client
|
||||
state = State("light.kitchen", "on")
|
||||
state = State(entity_entry.entity_id, "on")
|
||||
gconf = await cloud_client.get_google_config()
|
||||
|
||||
assert gconf.should_expose(state)
|
||||
|
||||
await cloud_client.prefs.async_update_google_entity_config(
|
||||
entity_id="light.kitchen", should_expose=False
|
||||
exposed_entities.async_expose_entity(
|
||||
"cloud.google_assistant", entity_entry.entity_id, False
|
||||
)
|
||||
|
||||
assert not gconf.should_expose(state)
|
||||
|
@ -262,14 +278,21 @@ async def test_google_config_should_2fa(
|
|||
hass: HomeAssistant, mock_cloud_setup, mock_cloud_login
|
||||
) -> None:
|
||||
"""Test Google config disabling 2FA method uses latest config."""
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
# Register a light entity
|
||||
entity_entry = entity_registry.async_get_or_create(
|
||||
"light", "test", "unique", suggested_object_id="kitchen"
|
||||
)
|
||||
|
||||
cloud_client = hass.data[DOMAIN].client
|
||||
gconf = await cloud_client.get_google_config()
|
||||
state = State("light.kitchen", "on")
|
||||
state = State(entity_entry.entity_id, "on")
|
||||
|
||||
assert gconf.should_2fa(state)
|
||||
|
||||
await cloud_client.prefs.async_update_google_entity_config(
|
||||
entity_id="light.kitchen", disable_2fa=True
|
||||
entity_registry.async_update_entity_options(
|
||||
entity_entry.entity_id, "cloud.google_assistant", {"disable_2fa": True}
|
||||
)
|
||||
|
||||
assert not gconf.should_2fa(state)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue