diff --git a/homeassistant/components/google_assistant/const.py b/homeassistant/components/google_assistant/const.py index 07506611109e5..e5d562057f3df 100644 --- a/homeassistant/components/google_assistant/const.py +++ b/homeassistant/components/google_assistant/const.py @@ -49,6 +49,7 @@ TYPE_GARAGE = PREFIX_TYPES + 'GARAGE' TYPE_OUTLET = PREFIX_TYPES + 'OUTLET' TYPE_SENSOR = PREFIX_TYPES + 'SENSOR' +TYPE_DOOR = PREFIX_TYPES + 'DOOR' SERVICE_REQUEST_SYNC = 'request_sync' HOMEGRAPH_URL = 'https://homegraph.googleapis.com/' @@ -93,9 +94,10 @@ DEVICE_CLASS_TO_GOOGLE_TYPES = { (cover.DOMAIN, cover.DEVICE_CLASS_GARAGE): TYPE_GARAGE, + (cover.DOMAIN, cover.DEVICE_CLASS_DOOR): TYPE_DOOR, (switch.DOMAIN, switch.DEVICE_CLASS_SWITCH): TYPE_SWITCH, (switch.DOMAIN, switch.DEVICE_CLASS_OUTLET): TYPE_OUTLET, - (binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_DOOR): TYPE_SENSOR, + (binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_DOOR): TYPE_DOOR, (binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_GARAGE_DOOR): TYPE_SENSOR, (binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_LOCK): TYPE_SENSOR, diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index 8ea6f26553de7..375f647da22dd 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -13,6 +13,8 @@ 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.binary_sensor import DemoBinarySensor +from homeassistant.components.demo.cover import DemoCover from homeassistant.components.demo.light import DemoLight from homeassistant.components.demo.switch import DemoSwitch @@ -598,6 +600,89 @@ async def test_device_class_switch(hass, device_class, google_type): } +@pytest.mark.parametrize("device_class,google_type", [ + ('door', 'action.devices.types.DOOR'), + ('garage_door', 'action.devices.types.SENSOR'), + ('lock', 'action.devices.types.SENSOR'), + ('opening', 'action.devices.types.SENSOR'), + ('window', 'action.devices.types.SENSOR'), +]) +async def test_device_class_binary_sensor(hass, device_class, google_type): + """Test that a binary entity syncs to the correct device type.""" + sensor = DemoBinarySensor( + 'Demo Sensor', + state=False, + device_class=device_class + ) + sensor.hass = hass + sensor.entity_id = 'binary_sensor.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': {'queryOnlyOpenClose': True}, + 'id': 'binary_sensor.demo_sensor', + 'name': {'name': 'Demo Sensor'}, + 'traits': ['action.devices.traits.OpenClose'], + 'type': google_type, + 'willReportState': False + }] + } + } + + +@pytest.mark.parametrize("device_class,google_type", [ + ('non_existing_class', 'action.devices.types.BLINDS'), + ('door', 'action.devices.types.DOOR'), +]) +async def test_device_class_cover(hass, device_class, google_type): + """Test that a binary entity syncs to the correct device type.""" + sensor = DemoCover( + hass, + 'Demo Sensor', + device_class=device_class + ) + sensor.hass = hass + sensor.entity_id = 'cover.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': 'cover.demo_sensor', + 'name': {'name': 'Demo Sensor'}, + 'traits': ['action.devices.traits.OpenClose'], + 'type': google_type, + 'willReportState': False + }] + } + } + + async def test_query_disconnect(hass): """Test a disconnect message.""" result = await sh.async_handle_message(