From a612d7a0f31f2a5835ebdede77d06015ff0c8578 Mon Sep 17 00:00:00 2001 From: uvjustin <46082645+uvjustin@users.noreply.github.com> Date: Fri, 22 Jul 2022 11:46:00 +0800 Subject: [PATCH] Round up for stream record lookback (#75580) --- homeassistant/components/stream/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/stream/__init__.py b/homeassistant/components/stream/__init__.py index f0b4ed99654..354f9a77672 100644 --- a/homeassistant/components/stream/__init__.py +++ b/homeassistant/components/stream/__init__.py @@ -503,15 +503,16 @@ class Stream: await self.start() + self._logger.debug("Started a stream recording of %s seconds", duration) + # Take advantage of lookback hls: HlsStreamOutput = cast(HlsStreamOutput, self.outputs().get(HLS_PROVIDER)) - if lookback > 0 and hls: - num_segments = min(int(lookback // hls.target_duration), MAX_SEGMENTS) + if hls: + num_segments = min(int(lookback / hls.target_duration) + 1, MAX_SEGMENTS) # Wait for latest segment, then add the lookback await hls.recv() recorder.prepend(list(hls.get_segments())[-num_segments - 1 : -1]) - self._logger.debug("Started a stream recording of %s seconds", duration) await recorder.async_record() async def async_get_image(