Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.unifiprotect.media_source.ProtectMediaSource Class Reference
Inheritance diagram for homeassistant.components.unifiprotect.media_source.ProtectMediaSource:
[legend]
Collaboration diagram for homeassistant.components.unifiprotect.media_source.ProtectMediaSource:
[legend]

Public Member Functions

None __init__ (self, HomeAssistant hass, dict[str, ProtectData] data_sources)
 
BrowseMediaSource async_browse_media (self, MediaSourceItem item)
 
er.EntityRegistry async_get_registry (self)
 
PlayMedia async_resolve_media (self, MediaSourceItem item)
 
- Public Member Functions inherited from homeassistant.components.media_source.models.MediaSource
None __init__ (self, str domain)
 

Public Attributes

 data_sources
 
 hass
 
- Public Attributes inherited from homeassistant.components.media_source.models.MediaSource
 domain
 
 name
 

Static Public Attributes

 str
 
- Static Public Attributes inherited from homeassistant.components.media_source.models.MediaSource
 None
 

Private Member Functions

str _breadcrumb (self, ProtectData data, str base_title, Camera|None camera=None, SimpleEventType|None event_type=None, int|None count=None)
 
BrowseMediaSource _build_camera (self, ProtectData data, str camera_id, bool build_children=False)
 
list[BrowseMediaSource_build_cameras (self, ProtectData data)
 
BrowseMediaSource _build_console (self, ProtectData data)
 
BrowseMediaSource _build_days (self, ProtectData data, str camera_id, SimpleEventType event_type, date start, bool is_all=True, bool build_children=False)
 
BrowseMediaSource _build_event (self, ProtectData data, dict[str, Any]|Event event, bool thumbnail_only=False)
 
list[BrowseMediaSource_build_events (self, ProtectData data, datetime start, datetime end, str|None camera_id=None, set[EventType]|None event_types=None, bool reserve=False)
 
BrowseMediaSource _build_events_type (self, ProtectData data, str camera_id, SimpleEventType event_type, bool build_children=False)
 
BrowseMediaSource _build_month (self, ProtectData data, str camera_id, SimpleEventType event_type, date start, bool build_children=False)
 
BrowseMediaSource _build_recent (self, ProtectData data, str camera_id, SimpleEventType event_type, int days, bool build_children=False)
 
BrowseMediaSource _build_sources (self)
 
str|None _get_camera_thumbnail_url (self, Camera camera)
 
tuple[date, bool, bool] _parse_range (self, list[str] parts)
 
BrowseMediaSource _resolve_event (self, ProtectData data, str event_id, bool thumbnail_only=False)
 

Private Attributes

 _registry
 

Detailed Description

Represents all UniFi Protect NVRs.

Definition at line 177 of file media_source.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.components.unifiprotect.media_source.ProtectMediaSource.__init__ (   self,
HomeAssistant  hass,
dict[str, ProtectData]   data_sources 
)
Initialize the UniFi Protect media source.

Definition at line 183 of file media_source.py.

Member Function Documentation

◆ _breadcrumb()

str homeassistant.components.unifiprotect.media_source.ProtectMediaSource._breadcrumb (   self,
ProtectData  data,
str  base_title,
Camera | None   camera = None,
SimpleEventType | None   event_type = None,
int | None   count = None 
)
private

Definition at line 390 of file media_source.py.

◆ _build_camera()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_camera (   self,
ProtectData  data,
str  camera_id,
bool   build_children = False 
)
private
Build media source for selectors for a UniFi Protect camera.

Definition at line 777 of file media_source.py.

◆ _build_cameras()

list[BrowseMediaSource] homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_cameras (   self,
ProtectData  data 
)
private
Build media source for a single UniFi Protect NVR.

Definition at line 840 of file media_source.py.

◆ _build_console()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_console (   self,
ProtectData  data 
)
private
Build media source for a single UniFi Protect NVR.

Definition at line 852 of file media_source.py.

◆ _build_days()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_days (   self,
ProtectData  data,
str  camera_id,
SimpleEventType  event_type,
date  start,
bool   is_all = True,
bool   build_children = False 
)
private
Build media source for events for a given day or whole month.

Definition at line 620 of file media_source.py.

◆ _build_event()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_event (   self,
ProtectData  data,
dict[str, Any] | Event  event,
bool   thumbnail_only = False 
)
private
Build media source for an individual event.

Definition at line 412 of file media_source.py.

◆ _build_events()

list[BrowseMediaSource] homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_events (   self,
ProtectData  data,
datetime  start,
datetime  end,
str | None   camera_id = None,
set[EventType] | None   event_types = None,
bool   reserve = False 
)
private
Build media source for a given range of time and event type.

Definition at line 474 of file media_source.py.

◆ _build_events_type()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_events_type (   self,
ProtectData  data,
str  camera_id,
SimpleEventType  event_type,
bool   build_children = False 
)
private
Build folder media source for a selectors for a given event type.

Definition at line 696 of file media_source.py.

◆ _build_month()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_month (   self,
ProtectData  data,
str  camera_id,
SimpleEventType  event_type,
date  start,
bool   build_children = False 
)
private
Build media source for selectors for a given month.

Definition at line 564 of file media_source.py.

◆ _build_recent()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_recent (   self,
ProtectData  data,
str  camera_id,
SimpleEventType  event_type,
int  days,
bool   build_children = False 
)
private
Build media source for events in relative days.

Definition at line 510 of file media_source.py.

◆ _build_sources()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._build_sources (   self)
private
Return all media source for all UniFi Protect NVRs.

Definition at line 867 of file media_source.py.

◆ _get_camera_thumbnail_url()

str | None homeassistant.components.unifiprotect.media_source.ProtectMediaSource._get_camera_thumbnail_url (   self,
Camera  camera 
)
private
Get camera thumbnail URL using the first available camera entity.

Definition at line 741 of file media_source.py.

◆ _parse_range()

tuple[date, bool, bool] homeassistant.components.unifiprotect.media_source.ProtectMediaSource._parse_range (   self,
list[str parts 
)
private

Definition at line 352 of file media_source.py.

◆ _resolve_event()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource._resolve_event (   self,
ProtectData  data,
str  event_id,
bool   thumbnail_only = False 
)
private
Resolve a specific event.

Definition at line 367 of file media_source.py.

◆ async_browse_media()

BrowseMediaSource homeassistant.components.unifiprotect.media_source.ProtectMediaSource.async_browse_media (   self,
MediaSourceItem  item 
)
Return a browsable UniFi Protect media source.

Identifier formatters for UniFi Protect media sources are all in IDs from
the UniFi Protect instance since events may not always map 1:1 to a Home
Assistant device or entity. It also drasically speeds up resolution.

The UniFi Protect Media source is timebased for the events recorded by the NVR.
So its structure is a bit different then many other media players. All browsable
media is a video clip. The media source could be greatly cleaned up if/when the
frontend has filtering supporting.

* ... Each NVR Console (hidden if there is only one)
    * All Cameras
    * ... Camera X
        * All Events
        * ... Event Type X
            * Last 24 Hours -> Events
            * Last 7 Days -> Events
            * Last 30 Days -> Events
            * ... This Month - X
                * Whole Month -> Events
                * ... Day X -> Events

Accepted identifier formats:

* {nvr_id}:event:{event_id}
    Specific Event for NVR
* {nvr_id}:eventthumb:{event_id}
    Specific Event Thumbnail for NVR
* {nvr_id}:browse
    Root NVR browse source
* {nvr_id}:browse:all|{camera_id}
    Root Camera(s) browse source
* {nvr_id}:browse:all|{camera_id}:all|{event_type}
    Root Camera(s) Event Type(s) browse source
* {nvr_id}:browse:all|{camera_id}:all|{event_type}:recent:{day_count}
    Listing of all events in last {day_count}, sorted in reverse chronological order
* {nvr_id}:browse:all|{camera_id}:all|{event_type}:range:{year}:{month}
    List of folders for each day in month + all events for month
* {nvr_id}:browse:all|{camera_id}:all|{event_type}:range:{year}:{month}:all|{day}
    Listing of all events for give {day} + {month} + {year} combination in chronological order

Reimplemented from homeassistant.components.media_source.models.MediaSource.

Definition at line 229 of file media_source.py.

◆ async_get_registry()

er.EntityRegistry homeassistant.components.unifiprotect.media_source.ProtectMediaSource.async_get_registry (   self)
Get or return Entity Registry.

Definition at line 384 of file media_source.py.

◆ async_resolve_media()

PlayMedia homeassistant.components.unifiprotect.media_source.ProtectMediaSource.async_resolve_media (   self,
MediaSourceItem  item 
)
Return a streamable URL and associated mime type for a UniFi Protect event.

Accepted identifier format are

* {nvr_id}:event:{event_id} - MP4 video clip for specific event
* {nvr_id}:eventthumb:{event_id} - Thumbnail JPEG for specific event

Reimplemented from homeassistant.components.media_source.models.MediaSource.

Definition at line 193 of file media_source.py.

Member Data Documentation

◆ _registry

homeassistant.components.unifiprotect.media_source.ProtectMediaSource._registry
private

Definition at line 191 of file media_source.py.

◆ data_sources

homeassistant.components.unifiprotect.media_source.ProtectMediaSource.data_sources

Definition at line 190 of file media_source.py.

◆ hass

homeassistant.components.unifiprotect.media_source.ProtectMediaSource.hass

Definition at line 189 of file media_source.py.

◆ str

homeassistant.components.unifiprotect.media_source.ProtectMediaSource.str
static

Definition at line 180 of file media_source.py.


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