mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +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 logging
|
||||||
import os
|
import os
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
|
import time
|
||||||
from typing import TYPE_CHECKING, Any, Final, cast, final
|
from typing import TYPE_CHECKING, Any, Final, cast, final
|
||||||
|
|
||||||
from aiohttp import hdrs, web
|
from aiohttp import hdrs, web
|
||||||
@ -294,6 +295,7 @@ async def async_get_still_stream(
|
|||||||
last_image = None
|
last_image = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
last_fetch = time.monotonic()
|
||||||
img_bytes = await image_cb()
|
img_bytes = await image_cb()
|
||||||
if not img_bytes:
|
if not img_bytes:
|
||||||
break
|
break
|
||||||
@ -307,7 +309,11 @@ async def async_get_still_stream(
|
|||||||
await write_to_mjpeg_stream(img_bytes)
|
await write_to_mjpeg_stream(img_bytes)
|
||||||
last_image = 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
|
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)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, preload_stream)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_tokens(time: datetime) -> None:
|
def update_tokens(t: datetime) -> None:
|
||||||
"""Update tokens of the entities."""
|
"""Update tokens of the entities."""
|
||||||
for entity in component.entities:
|
for entity in component.entities:
|
||||||
entity.async_update_token()
|
entity.async_update_token()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user