import datetime
from . import Stream as Stream
from .const import ATTR_STREAMS as ATTR_STREAMS, DOMAIN as DOMAIN, TARGET_SEGMENT_DURATION as TARGET_SEGMENT_DURATION
from aiohttp import web
from collections import deque
from homeassistant.components.http.view import HomeAssistantView as HomeAssistantView
from homeassistant.core import CALLBACK_TYPE as CALLBACK_TYPE, HomeAssistant as HomeAssistant, callback as callback
from homeassistant.helpers.event import async_call_later as async_call_later
from homeassistant.util.decorator import Registry as Registry
from typing import Any

PROVIDERS: Any

class Part:
    duration: float
    has_keyframe: bool
    data: bytes
    def __init__(self, duration, has_keyframe, data) -> None: ...
    def __lt__(self, other): ...
    def __le__(self, other): ...
    def __gt__(self, other): ...
    def __ge__(self, other): ...

class Segment:
    sequence: int
    init: bytes
    duration: float
    stream_id: int
    parts: list[Part]
    start_time: datetime.datetime
    @property
    def complete(self) -> bool: ...
    def get_bytes_without_init(self) -> bytes: ...
    def __init__(self, sequence, init, duration, stream_id, parts, start_time) -> None: ...
    def __lt__(self, other): ...
    def __le__(self, other): ...
    def __gt__(self, other): ...
    def __ge__(self, other): ...

class IdleTimer:
    _hass: Any
    _timeout: Any
    _callback: Any
    _unsub: Any
    idle: bool
    def __init__(self, hass: HomeAssistant, timeout: int, idle_callback: CALLBACK_TYPE) -> None: ...
    def start(self) -> None: ...
    def awake(self) -> None: ...
    def clear(self) -> None: ...
    def fire(self, _now: datetime.datetime) -> None: ...

class StreamOutput:
    _hass: Any
    idle_timer: Any
    _event: Any
    _segments: Any
    def __init__(self, hass: HomeAssistant, idle_timer: IdleTimer, deque_maxlen: Union[int, None] = ...) -> None: ...
    @property
    def name(self) -> Union[str, None]: ...
    @property
    def idle(self) -> bool: ...
    @property
    def last_sequence(self) -> int: ...
    @property
    def sequences(self) -> list[int]: ...
    @property
    def last_segment(self) -> Union[Segment, None]: ...
    @property
    def target_duration(self) -> float: ...
    def get_segment(self, sequence: int) -> Union[Segment, None]: ...
    def get_segments(self) -> deque[Segment]: ...
    async def recv(self) -> bool: ...
    def put(self, segment: Segment) -> None: ...
    def _async_put(self, segment: Segment) -> None: ...
    def cleanup(self) -> None: ...

class StreamView(HomeAssistantView):
    requires_auth: bool
    platform: Any
    async def get(self, request: web.Request, token: str, sequence: str = ...) -> web.StreamResponse: ...
    async def handle(self, request: web.Request, stream: Stream, sequence: str) -> web.StreamResponse: ...
