2022-01-20 20:32:28 +00:00
|
|
|
"""Diagnostics support for Renault."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
2022-01-20 22:02:47 +00:00
|
|
|
from homeassistant.components.diagnostics import async_redact_data
|
2022-01-20 20:32:28 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
2022-01-20 22:02:47 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-01-20 20:32:28 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceEntry
|
|
|
|
|
|
|
|
from . import RenaultHub
|
|
|
|
from .const import CONF_KAMEREON_ACCOUNT_ID, DOMAIN
|
|
|
|
|
2022-01-20 22:02:47 +00:00
|
|
|
TO_REDACT = {
|
2022-01-20 20:32:28 +00:00
|
|
|
CONF_KAMEREON_ACCOUNT_ID,
|
|
|
|
CONF_PASSWORD,
|
|
|
|
CONF_USERNAME,
|
|
|
|
"radioCode",
|
|
|
|
"registrationNumber",
|
|
|
|
"vin",
|
2022-01-20 22:02:47 +00:00
|
|
|
}
|
2022-01-20 20:32:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_get_config_entry_diagnostics(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry
|
|
|
|
) -> dict[str, Any]:
|
|
|
|
"""Return diagnostics for a config entry."""
|
|
|
|
renault_hub: RenaultHub = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
|
|
|
|
return {
|
|
|
|
"entry": {
|
|
|
|
"title": entry.title,
|
2022-01-20 22:02:47 +00:00
|
|
|
"data": async_redact_data(entry.data, TO_REDACT),
|
2022-01-20 20:32:28 +00:00
|
|
|
},
|
|
|
|
"vehicles": [
|
2022-01-20 22:02:47 +00:00
|
|
|
async_redact_data(vehicle.details.raw_data, TO_REDACT)
|
2022-01-20 20:32:28 +00:00
|
|
|
for vehicle in renault_hub.vehicles.values()
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def async_get_device_diagnostics(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry
|
|
|
|
) -> dict:
|
|
|
|
"""Return diagnostics for a device."""
|
|
|
|
renault_hub: RenaultHub = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
vin = next(iter(device.identifiers))[1]
|
|
|
|
|
|
|
|
return {
|
2022-01-20 22:02:47 +00:00
|
|
|
"details": async_redact_data(
|
|
|
|
renault_hub.vehicles[vin].details.raw_data, TO_REDACT
|
|
|
|
),
|
2022-01-20 20:32:28 +00:00
|
|
|
}
|