mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Increase test coverage for nest camera (#44144)
This commit is contained in:
parent
d1fb554e33
commit
6d12e764b7
@ -578,7 +578,6 @@ omit =
|
|||||||
homeassistant/components/nest/binary_sensor.py
|
homeassistant/components/nest/binary_sensor.py
|
||||||
homeassistant/components/nest/camera.py
|
homeassistant/components/nest/camera.py
|
||||||
homeassistant/components/nest/camera_legacy.py
|
homeassistant/components/nest/camera_legacy.py
|
||||||
homeassistant/components/nest/camera_sdm.py
|
|
||||||
homeassistant/components/nest/climate.py
|
homeassistant/components/nest/climate.py
|
||||||
homeassistant/components/nest/climate_legacy.py
|
homeassistant/components/nest/climate_legacy.py
|
||||||
homeassistant/components/nest/climate_sdm.py
|
homeassistant/components/nest/climate_sdm.py
|
||||||
|
@ -95,9 +95,10 @@ class NestCamera(Camera):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
|
supported_features = 0
|
||||||
if CameraLiveStreamTrait.NAME in self._device.traits:
|
if CameraLiveStreamTrait.NAME in self._device.traits:
|
||||||
return SUPPORT_STREAM
|
supported_features |= SUPPORT_STREAM
|
||||||
return 0
|
return supported_features
|
||||||
|
|
||||||
async def stream_source(self):
|
async def stream_source(self):
|
||||||
"""Return the source of the stream."""
|
"""Return the source of the stream."""
|
||||||
@ -131,7 +132,6 @@ class NestCamera(Camera):
|
|||||||
if not self._stream:
|
if not self._stream:
|
||||||
return
|
return
|
||||||
_LOGGER.debug("Extending stream url")
|
_LOGGER.debug("Extending stream url")
|
||||||
self._stream_refresh_unsub = None
|
|
||||||
try:
|
try:
|
||||||
self._stream = await self._stream.extend_rtsp_stream()
|
self._stream = await self._stream.extend_rtsp_stream()
|
||||||
except GoogleNestException as err:
|
except GoogleNestException as err:
|
||||||
|
@ -9,9 +9,11 @@ import datetime
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from google_nest_sdm.device import Device
|
from google_nest_sdm.device import Device
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import camera
|
from homeassistant.components import camera
|
||||||
from homeassistant.components.camera import STATE_IDLE
|
from homeassistant.components.camera import STATE_IDLE
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .common import async_setup_sdm_platform
|
from .common import async_setup_sdm_platform
|
||||||
@ -140,6 +142,36 @@ async def test_camera_stream(hass, auth):
|
|||||||
assert image.content == b"image bytes"
|
assert image.content == b"image bytes"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_camera_stream_missing_trait(hass, auth):
|
||||||
|
"""Test fetching a video stream when not supported by the API."""
|
||||||
|
traits = {
|
||||||
|
"sdm.devices.traits.Info": {
|
||||||
|
"customName": "My Camera",
|
||||||
|
},
|
||||||
|
"sdm.devices.traits.CameraImage": {
|
||||||
|
"maxImageResolution": {
|
||||||
|
"width": 800,
|
||||||
|
"height": 600,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await async_setup_camera(hass, traits, auth=auth)
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 1
|
||||||
|
cam = hass.states.get("camera.my_camera")
|
||||||
|
assert cam is not None
|
||||||
|
assert cam.state == STATE_IDLE
|
||||||
|
|
||||||
|
stream_source = await camera.async_get_stream_source(hass, "camera.my_camera")
|
||||||
|
assert stream_source is None
|
||||||
|
|
||||||
|
# Currently on support getting the image from a live stream
|
||||||
|
with pytest.raises(HomeAssistantError):
|
||||||
|
image = await camera.async_get_image(hass, "camera.my_camera")
|
||||||
|
assert image is None
|
||||||
|
|
||||||
|
|
||||||
async def test_refresh_expired_stream_token(hass, auth):
|
async def test_refresh_expired_stream_token(hass, auth):
|
||||||
"""Test a camera stream expiration and refresh."""
|
"""Test a camera stream expiration and refresh."""
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
@ -220,6 +252,59 @@ async def test_refresh_expired_stream_token(hass, auth):
|
|||||||
assert stream_source == "rtsp://some/url?auth=g.3.streamingToken"
|
assert stream_source == "rtsp://some/url?auth=g.3.streamingToken"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_stream_response_already_expired(hass, auth):
|
||||||
|
"""Test a API response returning an expired stream url."""
|
||||||
|
now = utcnow()
|
||||||
|
stream_1_expiration = now + datetime.timedelta(seconds=-90)
|
||||||
|
stream_2_expiration = now + datetime.timedelta(seconds=+90)
|
||||||
|
auth.responses = [
|
||||||
|
aiohttp.web.json_response(
|
||||||
|
{
|
||||||
|
"results": {
|
||||||
|
"streamUrls": {
|
||||||
|
"rtspUrl": "rtsp://some/url?auth=g.1.streamingToken"
|
||||||
|
},
|
||||||
|
"streamExtensionToken": "g.1.extensionToken",
|
||||||
|
"streamToken": "g.1.streamingToken",
|
||||||
|
"expiresAt": stream_1_expiration.isoformat(timespec="seconds"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
aiohttp.web.json_response(
|
||||||
|
{
|
||||||
|
"results": {
|
||||||
|
"streamUrls": {
|
||||||
|
"rtspUrl": "rtsp://some/url?auth=g.2.streamingToken"
|
||||||
|
},
|
||||||
|
"streamExtensionToken": "g.2.extensionToken",
|
||||||
|
"streamToken": "g.2.streamingToken",
|
||||||
|
"expiresAt": stream_2_expiration.isoformat(timespec="seconds"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
await async_setup_camera(
|
||||||
|
hass,
|
||||||
|
DEVICE_TRAITS,
|
||||||
|
auth=auth,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 1
|
||||||
|
cam = hass.states.get("camera.my_camera")
|
||||||
|
assert cam is not None
|
||||||
|
assert cam.state == STATE_IDLE
|
||||||
|
|
||||||
|
# The stream is expired, but we return it anyway
|
||||||
|
stream_source = await camera.async_get_stream_source(hass, "camera.my_camera")
|
||||||
|
assert stream_source == "rtsp://some/url?auth=g.1.streamingToken"
|
||||||
|
|
||||||
|
await fire_alarm(hass, now)
|
||||||
|
|
||||||
|
# Second attempt sees that the stream is expired and refreshes
|
||||||
|
stream_source = await camera.async_get_stream_source(hass, "camera.my_camera")
|
||||||
|
assert stream_source == "rtsp://some/url?auth=g.2.streamingToken"
|
||||||
|
|
||||||
|
|
||||||
async def test_camera_removed(hass, auth):
|
async def test_camera_removed(hass, auth):
|
||||||
"""Test case where entities are removed and stream tokens expired."""
|
"""Test case where entities are removed and stream tokens expired."""
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user