mirror of
https://github.com/home-assistant/core.git
synced 2026-09-13 04:01:03 +01:00
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Diagnostics support for Sofar."""
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.components.diagnostics import async_redact_data
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .coordinator import SofarConfigEntry
|
|
|
|
TO_REDACT = {"serial_number"}
|
|
|
|
_SERIAL_NUMBER_REGISTERS = range(0x0445, 0x044C)
|
|
|
|
|
|
async def async_get_config_entry_diagnostics(
|
|
hass: HomeAssistant, entry: SofarConfigEntry
|
|
) -> dict[str, Any]:
|
|
"""Return diagnostics for a config entry."""
|
|
device = entry.runtime_data.readings.device
|
|
raw = await device.async_read_raw()
|
|
if (holding := raw.get("holding")) is not None:
|
|
for address in _SERIAL_NUMBER_REGISTERS:
|
|
holding.pop(address, None)
|
|
|
|
return async_redact_data(
|
|
{
|
|
"model": device.model,
|
|
"inverter_type": device.inverter_type,
|
|
"serial_number": device.serial_number,
|
|
"readings_components": device.readings_components,
|
|
"settings_components": device.settings_components,
|
|
"active_faults": sorted(fault.key for fault in device.state.active_faults),
|
|
"address_masks": await device.async_read_masks(),
|
|
"raw": raw,
|
|
},
|
|
TO_REDACT,
|
|
)
|