From 0d4a6134c8c6f5a607bddb4d1c4167658c17b9c6 Mon Sep 17 00:00:00 2001 From: Malene Trab Date: Wed, 21 Feb 2024 08:23:13 +0000 Subject: [PATCH] Add diagnostics --- .../webastoconnect/diagnostics.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 custom_components/webastoconnect/diagnostics.py diff --git a/custom_components/webastoconnect/diagnostics.py b/custom_components/webastoconnect/diagnostics.py new file mode 100644 index 0000000..638715f --- /dev/null +++ b/custom_components/webastoconnect/diagnostics.py @@ -0,0 +1,52 @@ +"""Get diagnostics.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ( + CONF_EMAIL, + CONF_PASSWORD, + CONF_LATITUDE, + CONF_LONGITUDE, +) +from homeassistant.core import HomeAssistant + +from .api import WebastoConnectUpdateCoordinator +from .const import DOMAIN, ATTR_COORDINATOR + + +TO_REDACT = { + CONF_PASSWORD, + CONF_EMAIL, + CONF_LATITUDE, + CONF_LONGITUDE, + "lat", + "lon", + "acc_email", + "stripe_key", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + data_entry = hass.data[DOMAIN][entry.entry_id] + + data_dict = { + "entry": entry.as_dict(), + } + + device_dict = {} + api: WebastoConnectUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][ + ATTR_COORDINATOR + ] + + data_dict.update({"Latest API dataset": api.cloud._last_data}) + data_dict.update({"Latest device dataset": api.cloud._dev_data}) + data_dict.update({"Latest settings dataset": api.cloud._settings}) + + return async_redact_data(data_dict, TO_REDACT)