Skip to content

Commit d5a553c

Browse files
ptarjanedenhaus
andauthored
Fix Ring integration log flooding for accounts without subscription (#158012)
Co-authored-by: Robert Resch <[email protected]>
1 parent 9169b68 commit d5a553c

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

homeassistant/components/ring/camera.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ def _handle_coordinator_update(self) -> None:
128128
self._device = self._get_coordinator_data().get_video_device(
129129
self._device.device_api_id
130130
)
131+
131132
history_data = self._device.last_history
132-
if history_data:
133+
if history_data and self._device.has_subscription:
133134
self._last_event = history_data[0]
134135
# will call async_update to update the attributes and get the
135136
# video url from the api
@@ -154,8 +155,16 @@ async def async_camera_image(
154155
self, width: int | None = None, height: int | None = None
155156
) -> bytes | None:
156157
"""Return a still image response from the camera."""
158+
if self._video_url is None:
159+
if not self._device.has_subscription:
160+
raise HomeAssistantError(
161+
translation_domain=DOMAIN,
162+
translation_key="no_subscription",
163+
)
164+
return None
165+
157166
key = (width, height)
158-
if not (image := self._images.get(key)) and self._video_url is not None:
167+
if not (image := self._images.get(key)):
159168
image = await ffmpeg.async_get_image(
160169
self.hass,
161170
self._video_url,

homeassistant/components/ring/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
"api_timeout": {
152152
"message": "Timeout communicating with Ring API"
153153
},
154+
"no_subscription": {
155+
"message": "Ring Protect subscription required for snapshots"
156+
},
154157
"sdp_m_line_index_required": {
155158
"message": "Error negotiating stream for {device}"
156159
}

tests/components/ring/test_camera.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,38 @@ async def test_camera_image(
325325
assert image.content == SMALLEST_VALID_JPEG_BYTES
326326

327327

328+
async def test_camera_live_view_no_subscription(
329+
hass: HomeAssistant,
330+
mock_ring_client,
331+
mock_ring_devices,
332+
freezer: FrozenDateTimeFactory,
333+
) -> None:
334+
"""Test live view camera skips recording URL when no subscription."""
335+
await setup_platform(hass, Platform.CAMERA)
336+
337+
front_camera_mock = mock_ring_devices.get_device(765432)
338+
# Set device to not have subscription
339+
front_camera_mock.has_subscription = False
340+
341+
state = hass.states.get("camera.front_live_view")
342+
assert state is not None
343+
344+
# Reset mock call counts
345+
front_camera_mock.async_recording_url.reset_mock()
346+
347+
# Trigger coordinator update
348+
freezer.tick(SCAN_INTERVAL)
349+
async_fire_time_changed(hass)
350+
await hass.async_block_till_done(wait_background_tasks=True)
351+
352+
# For cameras without subscription, recording URL should NOT be fetched
353+
front_camera_mock.async_recording_url.assert_not_called()
354+
355+
# Requesting an image without subscription should raise an error
356+
with pytest.raises(HomeAssistantError):
357+
await async_get_image(hass, "camera.front_live_view")
358+
359+
328360
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
329361
async def test_camera_stream_attributes(
330362
hass: HomeAssistant,

0 commit comments

Comments
 (0)