mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Expose door cover/binary_sensor as door type (#23307)
* 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
This commit is contained in:
parent
6681605c34
commit
7c55b9f087
@ -50,6 +50,7 @@ TYPE_BLINDS = PREFIX_TYPES + 'BLINDS'
|
||||
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/'
|
||||
@ -94,9 +95,10 @@ DOMAIN_TO_GOOGLE_TYPES = {
|
||||
|
||||
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,
|
||||
|
@ -13,6 +13,8 @@ from homeassistant.components.climate.const import (
|
||||
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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user