Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion homeassistant/components/google_assistant/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ async def sync_serialize(self):
if not traits:
return None

device_type = get_google_type(domain,
device_class)

# If no device type found, skip
if not device_type:
return None

device = {
'id': state.entity_id,
'name': {
Expand All @@ -149,7 +156,7 @@ async def sync_serialize(self):
'attributes': {},
'traits': [trait.name for trait in traits],
'willReportState': False,
'type': get_google_type(domain, device_class),
'type': device_type,
}

# use aliases
Expand Down
32 changes: 32 additions & 0 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const, trait, helpers, smart_home as sh,
EVENT_COMMAND_RECEIVED, EVENT_QUERY_RECEIVED, EVENT_SYNC_RECEIVED)
from homeassistant.components.demo.light import DemoLight
from homeassistant.components.demo.binary_sensor import DemoBinarySensor
from homeassistant.components.demo.switch import DemoSwitch

from homeassistant.helpers import device_registry
Expand Down Expand Up @@ -558,6 +559,37 @@ async def test_empty_name_doesnt_sync(hass):
}


async def test_missing_device_type_doesnt_sync(hass):
"""Test that an entity without device class and no default doesn't sync."""
light = DemoBinarySensor(
'Demo Sensor',
state=False,
device_class='dummy_class'
)
light.hass = hass
light.entity_id = 'binary_sensor.demo_sensor'
await light.async_update_ha_state()

with patch('homeassistant.components.google_assistant.'
'trait.OpenCloseTrait.supported', return_value=True):
result = await sh.async_handle_message(
hass, BASIC_CONFIG, 'test-agent',
{
"requestId": REQ_ID,
"inputs": [{
"intent": "action.devices.SYNC"
}]
})

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


@pytest.mark.parametrize("device_class,google_type", [
('non_existing_class', 'action.devices.types.SWITCH'),
('switch', 'action.devices.types.SWITCH'),
Expand Down