Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagnostics download #46

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions custom_components/webastoconnect/diagnostics.py
Original file line number Diff line number Diff line change
@@ -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)
Loading