Improve nest camera failure handling on removal (#63207)
This commit is contained in:
parent
17b6f7ec88
commit
d6c8f3965a
2 changed files with 36 additions and 2 deletions
|
@ -194,7 +194,12 @@ class NestCamera(Camera):
|
|||
"""Invalidates the RTSP token when unloaded."""
|
||||
if self._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:
|
||||
self._stream_refresh_unsub()
|
||||
self._event_id = None
|
||||
|
|
|
@ -397,7 +397,7 @@ async def test_stream_response_already_expired(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(
|
||||
hass,
|
||||
DEVICE_TRAITS,
|
||||
|
@ -433,6 +433,35 @@ async def test_camera_removed(hass, auth):
|
|||
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):
|
||||
"""Tests a failure when refreshing the stream."""
|
||||
now = utcnow()
|
||||
|
|
Loading…
Add table
Reference in a new issue