Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
Expose door cover/binary_sensor as door type (home-assistant#23307)
Browse files Browse the repository at this point in the history
* Expose door cover/binary_sensor as door type

More logical to ask "What doors are open" than "What sensors are open"

* Add test for binary_sensor device_classes

* Cosmetic flake8

* Add test for device class for cover
  • Loading branch information
elupus authored and vagrant committed May 6, 2019
1 parent 7497cae commit b3a6311
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 43 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/google_assistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -94,9 +95,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
43 changes: 1 addition & 42 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ 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.GARAGE'),
('garage_door', 'action.devices.types.SENSOR'),
('lock', 'action.devices.types.SENSOR'),
('opening', 'action.devices.types.SENSOR'),
('window', 'action.devices.types.SENSOR'),
Expand Down Expand Up @@ -647,7 +647,6 @@ async def test_device_class_binary_sensor(hass, device_class, google_type):
@pytest.mark.parametrize("device_class,google_type", [
('non_existing_class', 'action.devices.types.BLINDS'),
('door', 'action.devices.types.DOOR'),
('garage', 'action.devices.types.GARAGE'),
])
async def test_device_class_cover(hass, device_class, google_type):
"""Test that a binary entity syncs to the correct device type."""
Expand Down Expand Up @@ -685,46 +684,6 @@ async def test_device_class_cover(hass, device_class, google_type):
}


@pytest.mark.parametrize("device_class,google_type", [
('non_existing_class', 'action.devices.types.MEDIA'),
('speaker', 'action.devices.types.SPEAKER'),
('tv', 'action.devices.types.TV'),
])
async def test_device_media_player(hass, device_class, google_type):
"""Test that a binary entity syncs to the correct device type."""
sensor = AbstractDemoPlayer(
'Demo',
device_class=device_class
)
sensor.hass = hass
sensor.entity_id = 'media_player.demo'
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': sensor.entity_id,
'name': {'name': sensor.name},
'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(
Expand Down

0 comments on commit b3a6311

Please sign in to comment.