Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.stream.Stream Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass, str source, dict[str, str] pyav_options, StreamSettings stream_settings, DynamicStreamSettings dynamic_stream_settings, str|None stream_label=None)
 
StreamOutput add_provider (self, str fmt, int timeout=OUTPUT_IDLE_TIMEOUT)
 
bytes|None async_get_image (self, int|None width=None, int|None height=None, bool wait_for_next_keyframe=False)
 
None async_record (self, str video_path, int duration=30, int lookback=5)
 
bool available (self)
 
None check_idle (self)
 
str endpoint_url (self, str fmt)
 
dict[str, Any] get_diagnostics (self)
 
Mapping[str, StreamOutputoutputs (self)
 
None remove_provider (self, StreamOutput provider)
 
None set_update_callback (self, Callable[[], None] update_callback)
 
None start (self)
 
None stop (self)
 
None update_source (self, str new_source)
 

Public Attributes

 access_token
 
 dynamic_stream_settings
 
 hass
 
 pyav_options
 
 source
 

Private Member Functions

None _async_update_state (self, bool available)
 
None _run_worker (self)
 
None _set_state (self, bool available)
 
None _stop (self)
 

Private Attributes

 _available
 
 _diagnostics
 
 _fast_restart_once
 
 _keyframe_converter
 
 _logger
 
 _outputs
 
 _start_stop_lock
 
 _stream_label
 
 _stream_settings
 
 _thread
 
 _thread_quit
 
 _update_callback
 

Detailed Description

Represents a single stream.

Definition at line 274 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.stream.Stream.__init__ (   self,
HomeAssistant  hass,
str  source,
dict[str, str]  pyav_options,
StreamSettings  stream_settings,
DynamicStreamSettings  dynamic_stream_settings,
str | None   stream_label = None 
)
Initialize a stream.

Definition at line 277 of file __init__.py.

Member Function Documentation

◆ _async_update_state()

None homeassistant.components.stream.Stream._async_update_state (   self,
bool  available 
)
private
Set state and Run callback to notify state has been updated.

Definition at line 374 of file __init__.py.

◆ _run_worker()

None homeassistant.components.stream.Stream._run_worker (   self)
private
Handle consuming streams and restart keepalive streams.

Definition at line 419 of file __init__.py.

◆ _set_state()

None homeassistant.components.stream.Stream._set_state (   self,
bool  available 
)
private
Set the stream state by updating the callback.

Definition at line 412 of file __init__.py.

◆ _stop()

None homeassistant.components.stream.Stream._stop (   self)
private
Stop worker thread.

Uses an asyncio.Lock to avoid conflicts with start().

Definition at line 497 of file __init__.py.

◆ add_provider()

StreamOutput homeassistant.components.stream.Stream.add_provider (   self,
str  fmt,
int   timeout = OUTPUT_IDLE_TIMEOUT 
)
Add provider output stream.

Definition at line 326 of file __init__.py.

◆ async_get_image()

bytes | None homeassistant.components.stream.Stream.async_get_image (   self,
int | None   width = None,
int | None   height = None,
bool   wait_for_next_keyframe = False 
)
Fetch an image from the Stream and return it as a jpeg in bytes.

Calls async_get_image from KeyFrameConverter. async_get_image should only be
called directly from the main loop and not from an executor thread as it uses
hass.add_executor_job underneath the hood.

Definition at line 550 of file __init__.py.

◆ async_record()

None homeassistant.components.stream.Stream.async_record (   self,
str  video_path,
int   duration = 30,
int   lookback = 5 
)
Make a .mp4 recording from a provided stream.

Definition at line 512 of file __init__.py.

◆ available()

bool homeassistant.components.stream.Stream.available (   self)
Return False if the stream is started and known to be unavailable.

Definition at line 365 of file __init__.py.

◆ check_idle()

None homeassistant.components.stream.Stream.check_idle (   self)
Reset access token if all providers are idle.

Definition at line 359 of file __init__.py.

◆ endpoint_url()

str homeassistant.components.stream.Stream.endpoint_url (   self,
str  fmt 
)
Start the stream and returns a url for the output format.

Definition at line 311 of file __init__.py.

◆ get_diagnostics()

dict[str, Any] homeassistant.components.stream.Stream.get_diagnostics (   self)
Return diagnostics information for the stream.

Definition at line 571 of file __init__.py.

◆ outputs()

Mapping[str, StreamOutput] homeassistant.components.stream.Stream.outputs (   self)
Return a copy of the stream outputs.

Definition at line 320 of file __init__.py.

◆ remove_provider()

None homeassistant.components.stream.Stream.remove_provider (   self,
StreamOutput  provider 
)
Remove provider output stream.

Definition at line 350 of file __init__.py.

◆ set_update_callback()

None homeassistant.components.stream.Stream.set_update_callback (   self,
Callable[[], None]  update_callback 
)
Set callback to run when state changes.

Definition at line 369 of file __init__.py.

◆ start()

None homeassistant.components.stream.Stream.start (   self)
Start a stream.

Uses an asyncio.Lock to avoid conflicts with _stop().

Definition at line 380 of file __init__.py.

◆ stop()

None homeassistant.components.stream.Stream.stop (   self)
Remove outputs and access token.

Definition at line 489 of file __init__.py.

◆ update_source()

None homeassistant.components.stream.Stream.update_source (   self,
str  new_source 
)
Restart the stream with a new stream source.

Definition at line 402 of file __init__.py.

Member Data Documentation

◆ _available

homeassistant.components.stream.Stream._available
private

Definition at line 376 of file __init__.py.

◆ _diagnostics

homeassistant.components.stream.Stream._diagnostics
private

Definition at line 309 of file __init__.py.

◆ _fast_restart_once

homeassistant.components.stream.Stream._fast_restart_once
private

Definition at line 298 of file __init__.py.

◆ _keyframe_converter

homeassistant.components.stream.Stream._keyframe_converter
private

Definition at line 299 of file __init__.py.

◆ _logger

homeassistant.components.stream.Stream._logger
private

Definition at line 304 of file __init__.py.

◆ _outputs

homeassistant.components.stream.Stream._outputs
private

Definition at line 491 of file __init__.py.

◆ _start_stop_lock

homeassistant.components.stream.Stream._start_stop_lock
private

Definition at line 294 of file __init__.py.

◆ _stream_label

homeassistant.components.stream.Stream._stream_label
private

Definition at line 291 of file __init__.py.

◆ _stream_settings

homeassistant.components.stream.Stream._stream_settings
private

Definition at line 290 of file __init__.py.

◆ _thread

homeassistant.components.stream.Stream._thread
private

Definition at line 393 of file __init__.py.

◆ _thread_quit

homeassistant.components.stream.Stream._thread_quit
private

Definition at line 296 of file __init__.py.

◆ _update_callback

homeassistant.components.stream.Stream._update_callback
private

Definition at line 371 of file __init__.py.

◆ access_token

homeassistant.components.stream.Stream.access_token

Definition at line 316 of file __init__.py.

◆ dynamic_stream_settings

homeassistant.components.stream.Stream.dynamic_stream_settings

Definition at line 292 of file __init__.py.

◆ hass

homeassistant.components.stream.Stream.hass

Definition at line 287 of file __init__.py.

◆ pyav_options

homeassistant.components.stream.Stream.pyav_options

Definition at line 289 of file __init__.py.

◆ source

homeassistant.components.stream.Stream.source

Definition at line 288 of file __init__.py.


The documentation for this class was generated from the following file: