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 support for diagnostics #239

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions custom_components/polestar_api/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Provides diagnostics for Polestar API."""

from __future__ import annotations

from typing import Any

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.const import CONF_PASSWORD
from homeassistant.core import HomeAssistant

from .data import PolestarConfigEntry

TO_REDACT = {CONF_PASSWORD}


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: PolestarConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""

coordinator = entry.runtime_data.coordinator
cars = entry.runtime_data.cars
api = coordinator.polestar_api

return {
"config_entry_data": async_redact_data(dict(entry.data), TO_REDACT),
"cars": [{"vin": car.vin, "model": car.model} for car in cars],
"auth_api": {
"oidc_provider": api.auth.oidc_provider,
"access_token_valid": api.auth.is_token_valid(),
"endpoint": api.auth.api_url,
"status": api.auth.latest_call_code,
},
"data_api": {"endpoint": api.api_url, "status": api.latest_call_code},
}
1 change: 1 addition & 0 deletions custom_components/polestar_api/polestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __init__(
else:
_LOGGER.debug("Configure Polestar API client for all cars")
self.unique_id = unique_id
self.username = username
self.polestar_api = PolestarApi(
username=username,
password=password,
Expand Down
2 changes: 2 additions & 0 deletions custom_components/polestar_api/pypolestar/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(
self.oidc_configuration = {}
self.latest_call_code = None
self.logger = _LOGGER.getChild(unique_id) if unique_id else _LOGGER
self.oidc_provider = OIDC_PROVIDER_BASE_URL
self.api_url = API_AUTH_URL
self.gql_client = get_gql_client(url=API_AUTH_URL, client=self.client_session)

async def async_init(self) -> None:
Expand Down