Allow switches to be represented as outlets on google assistant (#23149)

* Add device class support for switch to support outlet type

* Add a test for cover device class sync

* Drop remnant unused import
This commit is contained in:
Joakim Plate authored and Paulus Schoutsen committed 2019-04-16 17:07:14 -07:00
1 parent e02a5f0b31
commit 1bfccd803f
5 files changed
+70 -1

No files matched your search

@@ -14,6 +14,7 @@ from homeassistant.components.google_assistant import (
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.switch import DemoSwitch
from homeassistant.helpers import device_registry
from tests.common import (mock_device_registry, mock_registry,
@@ -557,6 +558,49 @@ async def test_empty_name_doesnt_sync(hass):
}
@pytest.mark.parametrize("device_class,google_type", [
('non_existing_class', 'action.devices.types.SWITCH'),
('switch', 'action.devices.types.SWITCH'),
('outlet', 'action.devices.types.OUTLET')
])
async def test_device_class_switch(hass, device_class, google_type):
"""Test that a cover entity syncs to the correct device type."""
sensor = DemoSwitch(
'Demo Sensor',
state=False,
icon='mdi:switch',
assumed=False,
device_class=device_class
)
sensor.hass = hass
sensor.entity_id = 'switch.demo_sensor'
await sensor.async_update_ha_state()
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': [{
'attributes': {},
'id': 'switch.demo_sensor',
'name': {'name': 'Demo Sensor'},
'traits': ['action.devices.traits.OnOff'],
'type': google_type,
'willReportState': False
}]
}
}
async def test_query_disconnect(hass):
"""Test a disconnect message."""
result = await sh.async_handle_message(