mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve nest camera failure handling on removal (#63207)
This commit is contained in:
parent
17b6f7ec88
commit
d6c8f3965a
@ -194,7 +194,12 @@ class NestCamera(Camera):
|
|||||||
"""Invalidates the RTSP token when unloaded."""
|
"""Invalidates the RTSP token when unloaded."""
|
||||||
if self._stream:
|
if self._stream:
|
||||||
_LOGGER.debug("Invalidating stream")
|
_LOGGER.debug("Invalidating stream")
|
||||||
await self._stream.stop_rtsp_stream()
|
try:
|
||||||
|
await self._stream.stop_rtsp_stream()
|
||||||
|
except ApiException as err:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Failed to revoke stream token, will rely on ttl: %s", err
|
||||||
|
)
|
||||||
if self._stream_refresh_unsub:
|
if self._stream_refresh_unsub:
|
||||||
self._stream_refresh_unsub()
|
self._stream_refresh_unsub()
|
||||||
self._event_id = None
|
self._event_id = None
|
||||||
|
@ -397,7 +397,7 @@ async def test_stream_response_already_expired(hass, auth):
|
|||||||
|
|
||||||
|
|
||||||
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 revoked."""
|
||||||
subscriber = await async_setup_camera(
|
subscriber = await async_setup_camera(
|
||||||
hass,
|
hass,
|
||||||
DEVICE_TRAITS,
|
DEVICE_TRAITS,
|
||||||
@ -433,6 +433,35 @@ async def test_camera_removed(hass, auth):
|
|||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_camera_remove_failure(hass, auth):
|
||||||
|
"""Test case where revoking the stream token fails on unload."""
|
||||||
|
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_STREAMING
|
||||||
|
|
||||||
|
# Start a stream, exercising cleanup on remove
|
||||||
|
auth.responses = [
|
||||||
|
make_stream_url_response(),
|
||||||
|
# Stop command will get a failure response
|
||||||
|
aiohttp.web.Response(status=HTTPStatus.INTERNAL_SERVER_ERROR),
|
||||||
|
]
|
||||||
|
stream_source = await camera.async_get_stream_source(hass, "camera.my_camera")
|
||||||
|
assert stream_source == "rtsp://some/url?auth=g.0.streamingToken"
|
||||||
|
|
||||||
|
# Unload should succeed even if an RPC fails
|
||||||
|
for config_entry in hass.config_entries.async_entries(DOMAIN):
|
||||||
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_refresh_expired_stream_failure(hass, auth):
|
async def test_refresh_expired_stream_failure(hass, auth):
|
||||||
"""Tests a failure when refreshing the stream."""
|
"""Tests a failure when refreshing the stream."""
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user