mirror of
https://github.com/home-assistant/core.git
synced 2026-05-29 19:57:40 +01:00
d766aae436
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""Diagnostics support for UptimeRobot."""
|
|
|
|
from typing import Any
|
|
|
|
from pyuptimerobot import UptimeRobotException
|
|
|
|
from homeassistant.components.diagnostics import async_redact_data
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .coordinator import UptimeRobotConfigEntry
|
|
|
|
TO_REDACT = {"email"}
|
|
|
|
|
|
async def async_get_config_entry_diagnostics(
|
|
hass: HomeAssistant,
|
|
entry: UptimeRobotConfigEntry,
|
|
) -> dict[str, Any]:
|
|
"""Return diagnostics for a config entry."""
|
|
coordinator = entry.runtime_data
|
|
account: dict[str, Any] | str | None = None
|
|
try:
|
|
response = await coordinator.api.async_get_account_details()
|
|
except UptimeRobotException as err:
|
|
account = str(err)
|
|
else:
|
|
if (details := response.data) is not None:
|
|
account = {
|
|
"monitorsCount": details.monitorsCount,
|
|
"email": details.email,
|
|
}
|
|
|
|
return {
|
|
"account": async_redact_data(account, TO_REDACT),
|
|
"monitors": [
|
|
{
|
|
"id": monitor.id,
|
|
"type": monitor.type,
|
|
"interval": monitor.interval,
|
|
"status": monitor.status,
|
|
}
|
|
for monitor in coordinator.data.values()
|
|
],
|
|
}
|