mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Add camera/stream platform diagnostics, exercised with nest (#69780)
This commit is contained in:
parent
4317daaf08
commit
5e49457c65
31
homeassistant/components/camera/diagnostics.py
Normal file
31
homeassistant/components/camera/diagnostics.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
"""Diagnostics for camera."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
from . import _get_camera_from_entity_id
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
entity_registry = er.async_get(hass)
|
||||||
|
entities = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)
|
||||||
|
diagnostics = {}
|
||||||
|
for entity in entities:
|
||||||
|
if entity.domain != DOMAIN:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
camera = _get_camera_from_entity_id(hass, entity.entity_id)
|
||||||
|
except HomeAssistantError:
|
||||||
|
continue
|
||||||
|
diagnostics[entity.entity_id] = (
|
||||||
|
camera.stream.get_diagnostics() if camera.stream else {}
|
||||||
|
)
|
||||||
|
return diagnostics
|
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from google_nest_sdm import diagnostics
|
from google_nest_sdm import diagnostics
|
||||||
from google_nest_sdm.device import Device
|
from google_nest_sdm.device import Device
|
||||||
from google_nest_sdm.device_traits import InfoTrait
|
from google_nest_sdm.device_traits import InfoTrait
|
||||||
from google_nest_sdm.exceptions import ApiException
|
from google_nest_sdm.exceptions import ApiException
|
||||||
|
|
||||||
|
from homeassistant.components.camera import diagnostics as camera_diagnostics
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
@ -42,12 +45,18 @@ async def async_get_config_entry_diagnostics(
|
|||||||
return {"error": str(err)}
|
return {"error": str(err)}
|
||||||
if not nest_devices:
|
if not nest_devices:
|
||||||
return {}
|
return {}
|
||||||
return {
|
data: dict[str, Any] = {
|
||||||
**diagnostics.get_diagnostics(),
|
**diagnostics.get_diagnostics(),
|
||||||
"devices": [
|
"devices": [
|
||||||
nest_device.get_diagnostics() for nest_device in nest_devices.values()
|
nest_device.get_diagnostics() for nest_device in nest_devices.values()
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
camera_data = await camera_diagnostics.async_get_config_entry_diagnostics(
|
||||||
|
hass, config_entry
|
||||||
|
)
|
||||||
|
if camera_data:
|
||||||
|
data["camera"] = camera_data
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
async def async_get_device_diagnostics(
|
async def async_get_device_diagnostics(
|
||||||
|
@ -56,10 +56,35 @@ DEVICE_DIAGNOSTIC_DATA = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CAMERA_API_DATA = {
|
||||||
|
"name": NEST_DEVICE_ID,
|
||||||
|
"type": "sdm.devices.types.CAMERA",
|
||||||
|
"traits": {
|
||||||
|
"sdm.devices.traits.CameraLiveStream": {
|
||||||
|
"videoCodecs": "H264",
|
||||||
|
"supportedProtocols": ["RTSP"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
CAMERA_DIAGNOSTIC_DATA = {
|
||||||
|
"data": {
|
||||||
|
"name": "**REDACTED**",
|
||||||
|
"traits": {
|
||||||
|
"sdm.devices.traits.CameraLiveStream": {
|
||||||
|
"videoCodecs": "H264",
|
||||||
|
"supportedProtocols": ["RTSP"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"type": "sdm.devices.types.CAMERA",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def platforms() -> list[str]:
|
def platforms() -> list[str]:
|
||||||
"""Fixture to specify platforms to test."""
|
"""Fixture to specify platforms to test."""
|
||||||
return ["sensor"]
|
return ["sensor", "camera"]
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(
|
async def test_entry_diagnostics(
|
||||||
@ -152,3 +177,18 @@ async def test_legacy_config_entry_diagnostics(
|
|||||||
await setup_base_platform()
|
await setup_base_platform()
|
||||||
|
|
||||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {}
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_camera_diagnostics(
|
||||||
|
hass, hass_client, create_device, setup_platform, config_entry
|
||||||
|
):
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
create_device.create(raw_data=CAMERA_API_DATA)
|
||||||
|
await setup_platform()
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
# Test that only non identifiable device information is returned
|
||||||
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
|
"devices": [CAMERA_DIAGNOSTIC_DATA],
|
||||||
|
"camera": {"camera.camera": {}},
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user