mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add Axis camera sources to diagnostics (#97063)
This commit is contained in:
parent
e5747d3f4c
commit
1552319e94
@ -35,10 +35,16 @@ class AxisCamera(AxisEntity, MjpegCamera):
|
|||||||
|
|
||||||
_attr_supported_features = CameraEntityFeature.STREAM
|
_attr_supported_features = CameraEntityFeature.STREAM
|
||||||
|
|
||||||
|
_still_image_url: str
|
||||||
|
_mjpeg_url: str
|
||||||
|
_stream_source: str
|
||||||
|
|
||||||
def __init__(self, device: AxisNetworkDevice) -> None:
|
def __init__(self, device: AxisNetworkDevice) -> None:
|
||||||
"""Initialize Axis Communications camera component."""
|
"""Initialize Axis Communications camera component."""
|
||||||
AxisEntity.__init__(self, device)
|
AxisEntity.__init__(self, device)
|
||||||
|
|
||||||
|
self._generate_sources()
|
||||||
|
|
||||||
MjpegCamera.__init__(
|
MjpegCamera.__init__(
|
||||||
self,
|
self,
|
||||||
username=device.username,
|
username=device.username,
|
||||||
@ -46,41 +52,52 @@ class AxisCamera(AxisEntity, MjpegCamera):
|
|||||||
mjpeg_url=self.mjpeg_source,
|
mjpeg_url=self.mjpeg_source,
|
||||||
still_image_url=self.image_source,
|
still_image_url=self.image_source,
|
||||||
authentication=HTTP_DIGEST_AUTHENTICATION,
|
authentication=HTTP_DIGEST_AUTHENTICATION,
|
||||||
|
unique_id=f"{device.unique_id}-camera",
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_unique_id = f"{device.unique_id}-camera"
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe camera events."""
|
"""Subscribe camera events."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass, self.device.signal_new_address, self._new_address
|
self.hass, self.device.signal_new_address, self._generate_sources
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
def _new_address(self) -> None:
|
def _generate_sources(self) -> None:
|
||||||
"""Set new device address for video stream."""
|
"""Generate sources.
|
||||||
self._mjpeg_url = self.mjpeg_source
|
|
||||||
self._still_image_url = self.image_source
|
Additionally used when device change IP address.
|
||||||
|
"""
|
||||||
|
image_options = self.generate_options(skip_stream_profile=True)
|
||||||
|
self._still_image_url = f"http://{self.device.host}:{self.device.port}/axis-cgi/jpg/image.cgi{image_options}"
|
||||||
|
|
||||||
|
mjpeg_options = self.generate_options()
|
||||||
|
self._mjpeg_url = f"http://{self.device.host}:{self.device.port}/axis-cgi/mjpg/video.cgi{mjpeg_options}"
|
||||||
|
|
||||||
|
stream_options = self.generate_options(add_video_codec_h264=True)
|
||||||
|
self._stream_source = f"rtsp://{self.device.username}:{self.device.password}@{self.device.host}/axis-media/media.amp{stream_options}"
|
||||||
|
|
||||||
|
self.device.additional_diagnostics["camera_sources"] = {
|
||||||
|
"Image": self._still_image_url,
|
||||||
|
"MJPEG": self._mjpeg_url,
|
||||||
|
"Stream": f"rtsp://user:pass@{self.device.host}/axis-media/media.amp{stream_options}",
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def image_source(self) -> str:
|
def image_source(self) -> str:
|
||||||
"""Return still image URL for device."""
|
"""Return still image URL for device."""
|
||||||
options = self.generate_options(skip_stream_profile=True)
|
return self._still_image_url
|
||||||
return f"http://{self.device.host}:{self.device.port}/axis-cgi/jpg/image.cgi{options}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mjpeg_source(self) -> str:
|
def mjpeg_source(self) -> str:
|
||||||
"""Return mjpeg URL for device."""
|
"""Return mjpeg URL for device."""
|
||||||
options = self.generate_options()
|
return self._mjpeg_url
|
||||||
return f"http://{self.device.host}:{self.device.port}/axis-cgi/mjpg/video.cgi{options}"
|
|
||||||
|
|
||||||
async def stream_source(self) -> str:
|
async def stream_source(self) -> str:
|
||||||
"""Return the stream source."""
|
"""Return the stream source."""
|
||||||
options = self.generate_options(add_video_codec_h264=True)
|
return self._stream_source
|
||||||
return f"rtsp://{self.device.username}:{self.device.password}@{self.device.host}/axis-media/media.amp{options}"
|
|
||||||
|
|
||||||
def generate_options(
|
def generate_options(
|
||||||
self, skip_stream_profile: bool = False, add_video_codec_h264: bool = False
|
self, skip_stream_profile: bool = False, add_video_codec_h264: bool = False
|
||||||
|
@ -62,6 +62,8 @@ class AxisNetworkDevice:
|
|||||||
self.fw_version = api.vapix.firmware_version
|
self.fw_version = api.vapix.firmware_version
|
||||||
self.product_type = api.vapix.product_type
|
self.product_type = api.vapix.product_type
|
||||||
|
|
||||||
|
self.additional_diagnostics: dict[str, Any] = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host(self):
|
def host(self):
|
||||||
"""Return the host address of this device."""
|
"""Return the host address of this device."""
|
||||||
|
@ -21,7 +21,7 @@ async def async_get_config_entry_diagnostics(
|
|||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id]
|
device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id]
|
||||||
diag: dict[str, Any] = {}
|
diag: dict[str, Any] = device.additional_diagnostics.copy()
|
||||||
|
|
||||||
diag["config"] = async_redact_data(config_entry.as_dict(), REDACT_CONFIG)
|
diag["config"] = async_redact_data(config_entry.as_dict(), REDACT_CONFIG)
|
||||||
|
|
||||||
|
@ -38,6 +38,11 @@ async def test_entry_diagnostics(
|
|||||||
"unique_id": REDACTED,
|
"unique_id": REDACTED,
|
||||||
"disabled_by": None,
|
"disabled_by": None,
|
||||||
},
|
},
|
||||||
|
"camera_sources": {
|
||||||
|
"Image": "http://1.2.3.4:80/axis-cgi/jpg/image.cgi",
|
||||||
|
"MJPEG": "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi",
|
||||||
|
"Stream": "rtsp://user:pass@1.2.3.4/axis-media/media.amp?videocodec=h264",
|
||||||
|
},
|
||||||
"api_discovery": [
|
"api_discovery": [
|
||||||
{
|
{
|
||||||
"id": "api-discovery",
|
"id": "api-discovery",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user