1 """Support for Axis camera streaming."""
3 from urllib.parse
import urlencode
12 from .
import AxisConfigEntry
13 from .const
import DEFAULT_STREAM_PROFILE, DEFAULT_VIDEO_SOURCE
14 from .entity
import AxisEntity
15 from .hub
import AxisHub
20 config_entry: AxisConfigEntry,
21 async_add_entities: AddEntitiesCallback,
23 """Set up the Axis camera video stream."""
26 hub = config_entry.runtime_data
29 not (prop := hub.api.vapix.params.property_handler.get(
"0"))
30 or not prop.image_format
38 """Representation of a Axis camera."""
40 _attr_supported_features = CameraEntityFeature.STREAM
47 """Initialize Axis Communications camera component."""
48 AxisEntity.__init__(self, hub)
54 username=hub.config.username,
55 password=hub.config.password,
58 authentication=HTTP_DIGEST_AUTHENTICATION,
60 unique_id=f
"{hub.unique_id}-camera",
64 """Subscribe camera events."""
76 Additionally used when device change IP address.
78 proto = self.
hubhub.config.protocol
79 host = self.
hubhub.config.host
80 port = self.
hubhub.config.port
82 image_options = self.
generate_optionsgenerate_options(skip_stream_profile=
True)
84 f
"{proto}://{host}:{port}/axis-cgi/jpg/image.cgi{image_options}"
89 f
"{proto}://{host}:{port}/axis-cgi/mjpg/video.cgi{mjpeg_options}"
92 stream_options = self.
generate_optionsgenerate_options(add_video_codec_h264=
True)
94 f
"rtsp://{self.hub.config.username}:{self.hub.config.password}"
95 f
"@{self.hub.config.host}/axis-media/media.amp{stream_options}"
98 self.
hubhub.additional_diagnostics[
"camera_sources"] = {
101 "Stream": (f
"rtsp://user:pass@{host}/axis-media/media.amp{stream_options}"),
106 """Return still image URL for device."""
111 """Return mjpeg URL for device."""
115 """Return the stream source."""
119 self, skip_stream_profile: bool =
False, add_video_codec_h264: bool =
False
121 """Generate options for video stream."""
124 if add_video_codec_h264:
125 options_dict[
"videocodec"] =
"h264"
128 not skip_stream_profile
129 and self.
hubhub.config.stream_profile != DEFAULT_STREAM_PROFILE
131 options_dict[
"streamprofile"] = self.
hubhub.config.stream_profile
133 if self.
hubhub.config.video_source != DEFAULT_VIDEO_SOURCE:
134 options_dict[
"camera"] = self.
hubhub.config.video_source
138 return f
"?{urlencode(options_dict)}"
str generate_options(self, bool skip_stream_profile=False, bool add_video_codec_h264=False)
None _generate_sources(self)
None async_added_to_hass(self)
None __init__(self, AxisHub hub)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, AxisConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None filter_urllib3_logging()
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)