Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions homeassistant/components/google_assistant/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,23 @@ def sync_serialize(self):
if state.state == STATE_UNAVAILABLE:
return None

entity_config = self.config.entity_config.get(state.entity_id, {})
name = (entity_config.get(CONF_NAME) or state.name).strip()

# If an empty string
if not name:
return None

traits = self.traits()

# Found no supported traits for this entity
if not traits:
return None

entity_config = self.config.entity_config.get(state.entity_id, {})

device = {
'id': state.entity_id,
'name': {
'name': entity_config.get(CONF_NAME) or state.name
'name': name
},
'attributes': {},
'traits': [trait.name for trait in traits],
Expand Down
26 changes: 26 additions & 0 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,29 @@ async def test_unavailable_state_doesnt_sync(hass):
'devices': []
}
}


async def test_empty_name_doesnt_sync(hass):
"""Test that an entity with empty name does not sync over."""
light = DemoLight(
None, ' ',
state=False,
)
light.hass = hass
light.entity_id = 'light.demo_light'
await light.async_update_ha_state()

result = await sh.async_handle_message(hass, BASIC_CONFIG, {
"requestId": REQ_ID,
"inputs": [{
"intent": "action.devices.SYNC"
}]
})

assert result == {
'requestId': REQ_ID,
'payload': {
'agentUserId': 'test-agent',
'devices': []
}
}