Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose door cover/binary_sensor as door type #23307

Merged
merged 4 commits into from
Apr 24, 2019
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
4 changes: 3 additions & 1 deletion homeassistant/components/google_assistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down Expand Up @@ -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,
Expand Down
85 changes: 85 additions & 0 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect, as we have this map to TYPE_GARAGE ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently for the binary sensor only for cover.

('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(
Expand Down