Add diagnostics support to Tailscale (#64649)

This commit is contained in:
Franck Nijhof 2022-01-23 09:01:44 +01:00 committed by GitHub
parent db979fef6c
commit 0af369d8f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 142 additions and 1 deletions

View file

@ -0,0 +1,37 @@
"""Diagnostics support for Tailscale."""
from __future__ import annotations
import json
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from .const import CONF_TAILNET, DOMAIN
from .coordinator import TailscaleDataUpdateCoordinator
TO_REDACT = {
CONF_API_KEY,
CONF_TAILNET,
"addresses",
"device_id",
"endpoints",
"hostname",
"machine_key",
"name",
"node_key",
"user",
"user",
}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: TailscaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
# Round-trip via JSON to trigger serialization
devices = [json.loads(device.json()) for device in coordinator.data.values()]
return async_redact_data({"devices": devices}, TO_REDACT)