Do not sync entities with an empty name (#14181)
parent
46c260fd85
commit
5dcad89a0d
|
@ -102,18 +102,23 @@ class _GoogleEntity:
|
|||
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],
|
||||
|
|
|
@ -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': []
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue