mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix Generic Camera interval calculation (#105820)
This commit is contained in:
parent
50b960fb5e
commit
485a02c89d
@ -12,6 +12,7 @@ from functools import partial
|
||||
import logging
|
||||
import os
|
||||
from random import SystemRandom
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Final, cast, final
|
||||
|
||||
from aiohttp import hdrs, web
|
||||
@ -294,6 +295,7 @@ async def async_get_still_stream(
|
||||
last_image = None
|
||||
|
||||
while True:
|
||||
last_fetch = time.monotonic()
|
||||
img_bytes = await image_cb()
|
||||
if not img_bytes:
|
||||
break
|
||||
@ -307,7 +309,11 @@ async def async_get_still_stream(
|
||||
await write_to_mjpeg_stream(img_bytes)
|
||||
last_image = img_bytes
|
||||
|
||||
await asyncio.sleep(interval)
|
||||
next_fetch = last_fetch + interval
|
||||
now = time.monotonic()
|
||||
if next_fetch > now:
|
||||
sleep_time = next_fetch - now
|
||||
await asyncio.sleep(sleep_time)
|
||||
|
||||
return response
|
||||
|
||||
@ -411,7 +417,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, preload_stream)
|
||||
|
||||
@callback
|
||||
def update_tokens(time: datetime) -> None:
|
||||
def update_tokens(t: datetime) -> None:
|
||||
"""Update tokens of the entities."""
|
||||
for entity in component.entities:
|
||||
entity.async_update_token()
|
||||
|
Loading…
x
Reference in New Issue
Block a user