forked from wlcrs/huawei_solar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnostics.py
103 lines (84 loc) · 3.58 KB
/
diagnostics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""Diagnostics support for Huawei Solar."""
from __future__ import annotations
from importlib.metadata import version
from typing import Any
from huawei_solar import HuaweiEMMABridge, HuaweiSUN2000Bridge
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD
from homeassistant.core import HomeAssistant
from . import HuaweiSolarUpdateCoordinators
from .const import DATA_UPDATE_COORDINATORS, DOMAIN
TO_REDACT = {CONF_PASSWORD}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinators: list[HuaweiSolarUpdateCoordinators] = hass.data[DOMAIN][
entry.entry_id
][DATA_UPDATE_COORDINATORS]
diagnostics_data = {
"config_entry_data": async_redact_data(dict(entry.data), TO_REDACT),
"pymodbus_version": version("pymodbus"),
}
for ucs in coordinators:
if isinstance(ucs.bridge, HuaweiSUN2000Bridge):
diagnostics_data[
f"slave_{ucs.bridge.slave_id}"
] = await _build_sun2000_bridge_diagnostics_info(ucs.bridge)
elif isinstance(ucs.bridge, HuaweiEMMABridge):
diagnostics_data[
f"slave_{ucs.bridge.slave_id}"
] = await _build_emma_bridge_diagnostics_info(ucs.bridge)
else:
diagnostics_data[f"slave_{ucs.bridge.slave_id}"] = {
"_type": "Unknown",
"model_name": ucs.bridge.model_name,
"firmware_version": ucs.bridge.firmware_version,
"software_version": ucs.bridge.software_version,
}
diagnostics_data[f"slave_{ucs.bridge.slave_id}_inverter_data"] = (
ucs.inverter_update_coordinator.data
)
if ucs.power_meter_update_coordinator:
diagnostics_data[f"slave_{ucs.bridge.slave_id}_power_meter_data"] = (
ucs.power_meter_update_coordinator.data
)
if ucs.energy_storage_update_coordinator:
diagnostics_data[f"slave_{ucs.bridge.slave_id}_battery_data"] = (
ucs.energy_storage_update_coordinator.data
)
if ucs.configuration_update_coordinator:
diagnostics_data[f"slave_{ucs.bridge.slave_id}_config_data"] = (
ucs.configuration_update_coordinator.data
)
if ucs.optimizer_update_coordinator:
diagnostics_data[f"slave_{ucs.bridge.slave_id}_optimizer_data"] = (
ucs.optimizer_update_coordinator.data
)
return diagnostics_data
async def _build_sun2000_bridge_diagnostics_info(
bridge: HuaweiSUN2000Bridge,
) -> dict[str, Any]:
return {
"_type": "SUN2000",
"model_name": bridge.model_name,
"firmware_version": bridge.firmware_version,
"software_version": bridge.software_version,
"pv_string_count": bridge.pv_string_count,
"has_optimizers": bridge.has_optimizers,
"battery_type": bridge.battery_type,
"battery_1_type": bridge.battery_1_type,
"battery_2_type": bridge.battery_2_type,
"power_meter_type": bridge.power_meter_type,
"supports_capacity_control": bridge.supports_capacity_control,
}
async def _build_emma_bridge_diagnostics_info(
bridge: HuaweiEMMABridge,
) -> dict[str, Any]:
return {
"_type": "EMMA",
"model_name": bridge.model_name,
"firmware_version": bridge.firmware_version,
"software_version": bridge.software_version,
}