2022-01-19 08:30:48 +00:00
|
|
|
"""Diagnostics support for Nest."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-27 05:33:04 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2022-01-28 20:50:38 +00:00
|
|
|
from google_nest_sdm import diagnostics
|
2022-01-19 08:30:48 +00:00
|
|
|
from google_nest_sdm.device_traits import InfoTrait
|
|
|
|
|
2022-04-27 05:33:04 +00:00
|
|
|
from homeassistant.components.camera import diagnostics as camera_diagnostics
|
2024-11-28 19:45:27 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-03-30 02:56:03 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceEntry
|
2022-01-19 08:30:48 +00:00
|
|
|
|
2024-11-28 19:45:27 +00:00
|
|
|
from .types import NestConfigEntry
|
2022-01-19 08:30:48 +00:00
|
|
|
|
|
|
|
REDACT_DEVICE_TRAITS = {InfoTrait.NAME}
|
|
|
|
|
|
|
|
|
2022-03-30 02:56:03 +00:00
|
|
|
async def async_get_config_entry_diagnostics(
|
2024-11-28 19:45:27 +00:00
|
|
|
hass: HomeAssistant, config_entry: NestConfigEntry
|
2023-01-09 14:17:48 +00:00
|
|
|
) -> dict[str, Any]:
|
2022-03-30 02:56:03 +00:00
|
|
|
"""Return diagnostics for a config entry."""
|
2024-11-28 19:45:27 +00:00
|
|
|
if (
|
|
|
|
not hasattr(config_entry, "runtime_data")
|
|
|
|
or not config_entry.runtime_data
|
|
|
|
or not (nest_devices := config_entry.runtime_data.device_manager.devices)
|
|
|
|
):
|
2022-03-30 02:56:03 +00:00
|
|
|
return {}
|
2022-04-27 05:33:04 +00:00
|
|
|
data: dict[str, Any] = {
|
2022-01-28 20:50:38 +00:00
|
|
|
**diagnostics.get_diagnostics(),
|
2022-01-19 08:30:48 +00:00
|
|
|
"devices": [
|
2022-03-30 02:56:03 +00:00
|
|
|
nest_device.get_diagnostics() for nest_device in nest_devices.values()
|
2022-01-28 20:50:38 +00:00
|
|
|
],
|
2022-01-19 08:30:48 +00:00
|
|
|
}
|
2022-04-27 05:33:04 +00:00
|
|
|
camera_data = await camera_diagnostics.async_get_config_entry_diagnostics(
|
|
|
|
hass, config_entry
|
|
|
|
)
|
|
|
|
if camera_data:
|
|
|
|
data["camera"] = camera_data
|
|
|
|
return data
|
2022-01-19 08:30:48 +00:00
|
|
|
|
|
|
|
|
2022-03-30 02:56:03 +00:00
|
|
|
async def async_get_device_diagnostics(
|
|
|
|
hass: HomeAssistant,
|
2024-11-28 19:45:27 +00:00
|
|
|
config_entry: NestConfigEntry,
|
2022-03-30 02:56:03 +00:00
|
|
|
device: DeviceEntry,
|
2023-01-09 14:17:48 +00:00
|
|
|
) -> dict[str, Any]:
|
2022-03-30 02:56:03 +00:00
|
|
|
"""Return diagnostics for a device."""
|
2024-11-28 19:45:27 +00:00
|
|
|
nest_devices = config_entry.runtime_data.device_manager.devices
|
2022-03-30 02:56:03 +00:00
|
|
|
nest_device_id = next(iter(device.identifiers))[1]
|
|
|
|
nest_device = nest_devices.get(nest_device_id)
|
|
|
|
return nest_device.get_diagnostics() if nest_device else {}
|