From 826433b680b74018f28e11fcce177a45d82e2b3e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 2 Feb 2020 23:48:13 +0100 Subject: [PATCH] Fix device name Google Assistant when using aliases (#31416) * Fix device name Google Assistant when using aliases * Adjust cloud tests --- homeassistant/components/google_assistant/helpers.py | 2 +- tests/components/cloud/test_client.py | 2 +- tests/components/google_assistant/__init__.py | 5 ++++- tests/components/google_assistant/test_smart_home.py | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/google_assistant/helpers.py b/homeassistant/components/google_assistant/helpers.py index 983f638656d..f1b7a89bffe 100644 --- a/homeassistant/components/google_assistant/helpers.py +++ b/homeassistant/components/google_assistant/helpers.py @@ -399,7 +399,7 @@ class GoogleEntity: # use aliases aliases = entity_config.get(CONF_ALIASES) if aliases: - device["name"]["nicknames"] = aliases + device["name"]["nicknames"] = [name] + aliases if self.config.is_local_sdk_active: device["otherDeviceIds"] = [{"deviceId": self.entity_id}] diff --git a/tests/components/cloud/test_client.py b/tests/components/cloud/test_client.py index da20afba0b1..b9e6524b62e 100644 --- a/tests/components/cloud/test_client.py +++ b/tests/components/cloud/test_client.py @@ -121,7 +121,7 @@ async def test_handler_google_actions(hass): device = devices[0] assert device["id"] == "switch.test" assert device["name"]["name"] == "Config name" - assert device["name"]["nicknames"] == ["Config alias"] + assert device["name"]["nicknames"] == ["Config name", "Config alias"] assert device["type"] == "action.devices.types.SWITCH" assert device["roomHint"] == "living room" diff --git a/tests/components/google_assistant/__init__.py b/tests/components/google_assistant/__init__.py index 9ef0599d394..c0b5aa7b193 100644 --- a/tests/components/google_assistant/__init__.py +++ b/tests/components/google_assistant/__init__.py @@ -104,7 +104,10 @@ DEMO_DEVICES = [ }, { "id": "light.ceiling_lights", - "name": {"name": "Roof Lights", "nicknames": ["top lights", "ceiling lights"]}, + "name": { + "name": "Roof Lights", + "nicknames": ["Roof Lights", "top lights", "ceiling lights"], + }, "traits": [ "action.devices.traits.OnOff", "action.devices.traits.Brightness", diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index b3467eae326..aa073c699f8 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -92,7 +92,10 @@ async def test_sync_message(hass): "devices": [ { "id": "light.demo_light", - "name": {"name": "Demo Light", "nicknames": ["Hello", "World"]}, + "name": { + "name": "Demo Light", + "nicknames": ["Demo Light", "Hello", "World"], + }, "traits": [ trait.TRAIT_BRIGHTNESS, trait.TRAIT_ONOFF,