mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Improve performance of ring camera still images (#53803)
Co-authored-by: Pat Wood <prwood80@users.noreply.github.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
819fd811af
commit
3f2fad1a27
@ -52,6 +52,7 @@ class RingCam(RingEntityMixin, Camera):
|
||||
self._last_event = None
|
||||
self._last_video_id = None
|
||||
self._video_url = None
|
||||
self._image = None
|
||||
self._expires_at = dt_util.utcnow() - FORCE_REFRESH_INTERVAL
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
@ -80,6 +81,7 @@ class RingCam(RingEntityMixin, Camera):
|
||||
self._last_event = None
|
||||
self._last_video_id = None
|
||||
self._video_url = None
|
||||
self._image = None
|
||||
self._expires_at = dt_util.utcnow()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@ -106,12 +108,18 @@ class RingCam(RingEntityMixin, Camera):
|
||||
self, width: int | None = None, height: int | None = None
|
||||
) -> bytes | None:
|
||||
"""Return a still image response from the camera."""
|
||||
if self._video_url is None:
|
||||
return
|
||||
if self._image is None and self._video_url:
|
||||
image = await ffmpeg.async_get_image(
|
||||
self.hass,
|
||||
self._video_url,
|
||||
width=width,
|
||||
height=height,
|
||||
)
|
||||
|
||||
return await ffmpeg.async_get_image(
|
||||
self.hass, self._video_url, width=width, height=height
|
||||
)
|
||||
if image:
|
||||
self._image = image
|
||||
|
||||
return self._image
|
||||
|
||||
async def handle_async_mjpeg_stream(self, request):
|
||||
"""Generate an HTTP MJPEG stream from the camera."""
|
||||
@ -144,6 +152,9 @@ class RingCam(RingEntityMixin, Camera):
|
||||
if self._last_video_id == self._last_event["id"] and utcnow <= self._expires_at:
|
||||
return
|
||||
|
||||
if self._last_video_id != self._last_event["id"]:
|
||||
self._image = None
|
||||
|
||||
try:
|
||||
video_url = await self.hass.async_add_executor_job(
|
||||
self._device.recording_url, self._last_event["id"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user