From dc0c3a4d2dde52c4bb485e8b9758d517e1141703 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 23 Mar 2022 12:46:53 +0100 Subject: [PATCH] Exclude hidden entities from google_assistant (#68554) --- .../components/google_assistant/http.py | 5 ++++- .../google_assistant/test_google_assistant.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/google_assistant/http.py b/homeassistant/components/google_assistant/http.py index f068dabe47a..3f3db1f2b5b 100644 --- a/homeassistant/components/google_assistant/http.py +++ b/homeassistant/components/google_assistant/http.py @@ -126,7 +126,10 @@ class GoogleConfig(AbstractConfig): entity_registry = er.async_get(self.hass) registry_entry = entity_registry.async_get(state.entity_id) if registry_entry: - auxiliary_entity = registry_entry.entity_category is not None + auxiliary_entity = ( + registry_entry.entity_category is not None + or registry_entry.hidden_by is not None + ) else: auxiliary_entity = False diff --git a/tests/components/google_assistant/test_google_assistant.py b/tests/components/google_assistant/test_google_assistant.py index 0a916c1e184..fe86aae4b1a 100644 --- a/tests/components/google_assistant/test_google_assistant.py +++ b/tests/components/google_assistant/test_google_assistant.py @@ -21,6 +21,7 @@ from homeassistant.components import ( from homeassistant.components.climate import const as climate from homeassistant.components.humidifier import const as humidifier from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES +from homeassistant.helpers import entity_registry as er from . import DEMO_DEVICES @@ -151,11 +152,27 @@ async def test_sync_request(hass_fixture, assistant_client, auth_header): suggested_object_id="system_switch", entity_category="system", ) + entity_entry4 = entity_registry.async_get_or_create( + "switch", + "test", + "switch_hidden_integration_id", + suggested_object_id="hidden_integration_switch", + hidden_by=er.RegistryEntryHider.INTEGRATION, + ) + entity_entry5 = entity_registry.async_get_or_create( + "switch", + "test", + "switch_hidden_user_id", + suggested_object_id="hidden_user_switch", + hidden_by=er.RegistryEntryHider.USER, + ) # These should not show up in the sync request hass_fixture.states.async_set(entity_entry1.entity_id, "on") hass_fixture.states.async_set(entity_entry2.entity_id, "something_else") hass_fixture.states.async_set(entity_entry3.entity_id, "blah") + hass_fixture.states.async_set(entity_entry4.entity_id, "foo") + hass_fixture.states.async_set(entity_entry5.entity_id, "bar") reqid = "5711642932632160983" data = {"requestId": reqid, "inputs": [{"intent": "action.devices.SYNC"}]}