fix main stats of sinexcel battery view

This commit is contained in:
Yinyin Liu 2026-03-26 10:27:54 +01:00
parent 68d057b919
commit cc1ec216ee
1 changed files with 30 additions and 5 deletions

View File

@ -233,20 +233,45 @@ export const transformInputToBatteryViewDataJson = async (
}); });
} }
// Map category names to InverterRecord field suffixes const hasDevices = !!inv?.Devices;
const categoryFieldMap = {
// Sinexcel field suffixes differ from Growatt for Voltage/Current
const categoryFieldMapGrowatt = {
Soc: 'Soc', Soc: 'Soc',
Power: 'Power', Power: 'Power',
Voltage: 'Voltage', Voltage: 'Voltage',
Current: 'Current', Current: 'Current',
Soh: 'Soh' Soh: 'Soh'
}; };
const categoryFieldMapSinexcel = {
Soc: 'Soc',
Power: 'Power',
Voltage: 'PackTotalVoltage',
Current: 'PackTotalCurrent',
Soh: 'Soh'
};
for (let j = 0; j < pathsToSave.length; j++) { for (let j = 0; j < pathsToSave.length; j++) {
const batteryIndex = j + 1; // Battery1, Battery2, ...
categories.forEach((category) => { categories.forEach((category) => {
const fieldName = `Battery${batteryIndex}${categoryFieldMap[category]}`; let value: number | undefined;
const value = inv[fieldName];
if (hasDevices) {
// Sinexcel: nested under Devices — 0→D1/B1, 1→D1/B2, 2→D2/B1, ...
const deviceId = String(Math.floor(j / 2) + 1);
const bi = (j % 2) + 1;
const device = inv.Devices[deviceId];
const fieldName = `Battery${bi}${categoryFieldMapSinexcel[category]}`;
value = device?.[fieldName];
// Fallback for Soc
if ((value === undefined || value === null) && category === 'Soc') {
value = device?.[`Battery${bi}SocSecondvalue`];
}
} else {
// Growatt: flat Battery1Soc, Battery2Voltage, ...
const batteryIndex = j + 1;
const fieldName = `Battery${batteryIndex}${categoryFieldMapGrowatt[category]}`;
value = inv[fieldName];
}
if (value !== undefined && value !== null) { if (value !== undefined && value !== null) {
if (value < chartOverview[category].min) { if (value < chartOverview[category].min) {