Google Assistant: Add camera stream trait (#22278)
* Add camera stream trait * Lint
This commit is contained in:
1 parent
d81df1f0ae
commit
c68b621972
7 files changed
+176
-7
No files matched your search
@@ -1,10 +1,12 @@
|
||||
"""Test Google Smart Home."""
|
||||
from unittest.mock import patch, Mock
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import State, EVENT_CALL_SERVICE
|
||||
from homeassistant.const import (
|
||||
ATTR_SUPPORTED_FEATURES, ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_MIN_TEMP, ATTR_MAX_TEMP, STATE_HEAT, SUPPORT_OPERATION_MODE
|
||||
)
|
||||
@@ -15,7 +17,7 @@ from homeassistant.components.light.demo import DemoLight
|
||||
|
||||
from homeassistant.helpers import device_registry
|
||||
from tests.common import (mock_device_registry, mock_registry,
|
||||
mock_area_registry)
|
||||
mock_area_registry, mock_coro)
|
||||
|
||||
BASIC_CONFIG = helpers.Config(
|
||||
should_expose=lambda state: True,
|
||||
@@ -557,3 +559,57 @@ async def test_query_disconnect(hass):
|
||||
})
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
async def test_trait_execute_adding_query_data(hass):
|
||||
"""Test a trait execute influencing query data."""
|
||||
hass.config.api = Mock(base_url='http://1.1.1.1:8123')
|
||||
hass.states.async_set('camera.office', 'idle', {
|
||||
'supported_features': camera.SUPPORT_STREAM
|
||||
})
|
||||
|
||||
with patch('homeassistant.components.camera.async_request_stream',
|
||||
return_value=mock_coro('/api/streams/bla')):
|
||||
result = await sh.async_handle_message(
|
||||
hass, BASIC_CONFIG, None,
|
||||
{
|
||||
"requestId": REQ_ID,
|
||||
"inputs": [{
|
||||
"intent": "action.devices.EXECUTE",
|
||||
"payload": {
|
||||
"commands": [{
|
||||
"devices": [
|
||||
{"id": "camera.office"},
|
||||
],
|
||||
"execution": [{
|
||||
"command":
|
||||
"action.devices.commands.GetCameraStream",
|
||||
"params": {
|
||||
"StreamToChromecast": True,
|
||||
"SupportedStreamProtocols": [
|
||||
"progressive_mp4",
|
||||
"hls",
|
||||
"dash",
|
||||
"smooth_stream"
|
||||
]
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
||||
assert result == {
|
||||
"requestId": REQ_ID,
|
||||
"payload": {
|
||||
"commands": [{
|
||||
"ids": ['camera.office'],
|
||||
"status": "SUCCESS",
|
||||
"states": {
|
||||
"online": True,
|
||||
'cameraStreamAccessUrl':
|
||||
'http://1.1.1.1:8123/api/streams/bla',
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
"""Tests for the Google Assistant traits."""
|
||||
from unittest.mock import patch, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import (
|
||||
camera,
|
||||
cover,
|
||||
fan,
|
||||
input_boolean,
|
||||
@@ -21,7 +24,7 @@ from homeassistant.const import (
|
||||
TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE)
|
||||
from homeassistant.core import State, DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE
|
||||
from homeassistant.util import color
|
||||
from tests.common import async_mock_service
|
||||
from tests.common import async_mock_service, mock_coro
|
||||
|
||||
BASIC_CONFIG = helpers.Config(
|
||||
should_expose=lambda state: True,
|
||||
@@ -135,6 +138,35 @@ async def test_brightness_media_player(hass):
|
||||
}
|
||||
|
||||
|
||||
async def test_camera_stream(hass):
|
||||
"""Test camera stream trait support for camera domain."""
|
||||
hass.config.api = Mock(base_url='http://1.1.1.1:8123')
|
||||
assert trait.CameraStreamTrait.supported(camera.DOMAIN,
|
||||
camera.SUPPORT_STREAM)
|
||||
|
||||
trt = trait.CameraStreamTrait(
|
||||
hass, State('camera.bla', camera.STATE_IDLE, {}), BASIC_CONFIG
|
||||
)
|
||||
|
||||
assert trt.sync_attributes() == {
|
||||
'cameraStreamSupportedProtocols': [
|
||||
"hls",
|
||||
],
|
||||
'cameraStreamNeedAuthToken': False,
|
||||
'cameraStreamNeedDrmEncryption': False,
|
||||
}
|
||||
|
||||
assert trt.query_attributes() == {}
|
||||
|
||||
with patch('homeassistant.components.camera.async_request_stream',
|
||||
return_value=mock_coro('/api/streams/bla')):
|
||||
await trt.execute(trait.COMMAND_GET_CAMERA_STREAM, BASIC_DATA, {})
|
||||
|
||||
assert trt.query_attributes() == {
|
||||
'cameraStreamAccessUrl': 'http://1.1.1.1:8123/api/streams/bla'
|
||||
}
|
||||
|
||||
|
||||
async def test_onoff_group(hass):
|
||||
"""Test OnOff trait support for group domain."""
|
||||
assert trait.OnOffTrait.supported(group.DOMAIN, 0)
|
||||
|
||||
Reference in new issue
Block a user