Add diagnostics to Fully Kiosk Browser integration (#77274)

pull/77363/head
Charles Garwood 2022-08-26 09:21:45 -04:00 committed by GitHub
parent 38ca74b547
commit 36d77d1f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,64 @@
"""Provides diagnostics for Fully Kiosk Browser."""
from __future__ import annotations
from typing import Any
from homeassistant.components.diagnostics.util import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from .const import DOMAIN
DEVICE_INFO_TO_REDACT = {
"serial",
"Mac",
"ip6",
"hostname6",
"ip4",
"hostname4",
"deviceID",
"startUrl",
"currentPage",
"SSID",
"BSSID",
}
SETTINGS_TO_REDACT = {
"startURL",
"mqttBrokerPassword",
"mqttBrokerUsername",
"remoteAdminPassword",
"wifiKey",
"authPassword",
"authUsername",
"mqttBrokerUrl",
"kioskPin",
"wifiSSID",
"screensaverWallpaperURL",
"barcodeScanTargetUrl",
"launcherBgUrl",
"clientCaUrl",
"urlWhitelist",
"alarmSoundFileUrl",
"errorURL",
"actionBarIconUrl",
"kioskWifiPin",
"knoxApnConfig",
"injectJsCode",
"mdmApnConfig",
"mdmProxyConfig",
"wifiEnterpriseIdentity",
"sebExamKey",
"sebConfigKey",
"kioskPinEnc",
}
async def async_get_device_diagnostics(
hass: HomeAssistant, entry: ConfigEntry, device: dr.DeviceEntry
) -> dict[str, Any]:
"""Return device diagnostics."""
coordinator = hass.data[DOMAIN][entry.entry_id]
data = coordinator.data
data["settings"] = async_redact_data(data["settings"], SETTINGS_TO_REDACT)
return async_redact_data(data, DEVICE_INFO_TO_REDACT)

View File

@ -0,0 +1,43 @@
"""Test the Fully Kiosk Browser diagnostics."""
from unittest.mock import MagicMock
from aiohttp import ClientSession
from homeassistant.components.diagnostics.const import REDACTED
from homeassistant.components.fully_kiosk.const import DOMAIN
from homeassistant.components.fully_kiosk.diagnostics import (
DEVICE_INFO_TO_REDACT,
SETTINGS_TO_REDACT,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_device
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSession,
mock_fully_kiosk: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test Fully Kiosk diagnostics."""
device_registry = dr.async_get(hass)
device = device_registry.async_get_device({(DOMAIN, "abcdef-123456")})
diagnostics = await get_diagnostics_for_device(
hass, hass_client, init_integration, device
)
assert diagnostics
for key in DEVICE_INFO_TO_REDACT:
if hasattr(diagnostics, key):
assert diagnostics[key] == REDACTED
for key in SETTINGS_TO_REDACT:
if hasattr(diagnostics["settings"], key):
assert (
diagnostics["settings"][key] == REDACTED
or diagnostics["settings"][key] == ""
)