Add device classes for media player and map to google types (#23236)

* Add device classes for media player and map to google types

* Switch default class for media_player to media
This commit is contained in:
Joakim Plate authored and Paulus Schoutsen committed 2019-04-25 13:12:11 -07:00
1 parent 7e8f2d72b6
commit 39932d132d
5 files changed
+68 -6

No files matched your search

@@ -147,7 +147,7 @@ DEMO_DEVICES = [{
'action.devices.traits.Modes'
],
'type':
'action.devices.types.SWITCH',
'action.devices.types.MEDIA',
'willReportState':
False
}, {
@@ -162,7 +162,7 @@ DEMO_DEVICES = [{
'action.devices.traits.Modes'
],
'type':
'action.devices.types.SWITCH',
'action.devices.types.MEDIA',
'willReportState':
False
}, {
@@ -171,7 +171,7 @@ DEMO_DEVICES = [{
'name': 'Lounge room'
},
'traits': ['action.devices.traits.OnOff', 'action.devices.traits.Modes'],
'type': 'action.devices.types.SWITCH',
'type': 'action.devices.types.MEDIA',
'willReportState': False
}, {
'id':
@@ -182,7 +182,7 @@ DEMO_DEVICES = [{
'traits':
['action.devices.traits.OnOff', 'action.devices.traits.Volume'],
'type':
'action.devices.types.SWITCH',
'action.devices.types.MEDIA',
'willReportState':
False
}, {
@@ -16,6 +16,7 @@ from homeassistant.components.google_assistant import (
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.media_player import AbstractDemoPlayer
from homeassistant.components.demo.switch import DemoSwitch
from homeassistant.helpers import device_registry
@@ -684,6 +685,46 @@ 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(