Don't expose config or diagnostic entities to cloud (#57771)

This commit is contained in:
Erik Montnemery 2021-10-15 18:35:32 +02:00 committed by GitHub
parent 8b33aa3702
commit 0f2b5ea28e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 15 deletions

View file

@ -8,7 +8,7 @@ from homeassistant.components.cloud import ALEXA_SCHEMA, alexa_config
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.util.dt import utcnow
from tests.common import async_fire_time_changed
from tests.common import async_fire_time_changed, mock_registry
@pytest.fixture()
@ -19,6 +19,23 @@ def cloud_stub():
async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
"""Test Alexa config should expose using prefs."""
entity_registry = mock_registry(hass)
entity_entry1 = entity_registry.async_get_or_create(
"switch",
"test",
"switch_config_id",
suggested_object_id="config_switch",
entity_category="config",
)
entity_entry2 = entity_registry.async_get_or_create(
"switch",
"test",
"switch_diagnostic_id",
suggested_object_id="diagnostic_switch",
entity_category="diagnostic",
)
entity_conf = {"should_expose": False}
await cloud_prefs.async_update(
alexa_entity_configs={"light.kitchen": entity_conf},
@ -31,11 +48,20 @@ async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
await conf.async_initialize()
assert not conf.should_expose("light.kitchen")
assert not conf.should_expose(entity_entry1.entity_id)
assert not conf.should_expose(entity_entry2.entity_id)
entity_conf["should_expose"] = True
assert conf.should_expose("light.kitchen")
# config and diagnostic entities should not be exposed
assert not conf.should_expose(entity_entry1.entity_id)
assert not conf.should_expose(entity_entry2.entity_id)
entity_conf["should_expose"] = None
assert conf.should_expose("light.kitchen")
# config and diagnostic entities should not be exposed
assert not conf.should_expose(entity_entry1.entity_id)
assert not conf.should_expose(entity_entry2.entity_id)
assert "alexa" not in hass.config.components
await cloud_prefs.async_update(