diff --git a/typescript/frontend-marios2/src/interfaces/Chart.tsx b/typescript/frontend-marios2/src/interfaces/Chart.tsx index e41f0118c..6c5840cb5 100644 --- a/typescript/frontend-marios2/src/interfaces/Chart.tsx +++ b/typescript/frontend-marios2/src/interfaces/Chart.tsx @@ -233,20 +233,45 @@ export const transformInputToBatteryViewDataJson = async ( }); } - // Map category names to InverterRecord field suffixes - const categoryFieldMap = { + const hasDevices = !!inv?.Devices; + + // Sinexcel field suffixes differ from Growatt for Voltage/Current + const categoryFieldMapGrowatt = { Soc: 'Soc', Power: 'Power', Voltage: 'Voltage', Current: 'Current', Soh: 'Soh' }; + const categoryFieldMapSinexcel = { + Soc: 'Soc', + Power: 'Power', + Voltage: 'PackTotalVoltage', + Current: 'PackTotalCurrent', + Soh: 'Soh' + }; for (let j = 0; j < pathsToSave.length; j++) { - const batteryIndex = j + 1; // Battery1, Battery2, ... categories.forEach((category) => { - const fieldName = `Battery${batteryIndex}${categoryFieldMap[category]}`; - const value = inv[fieldName]; + let value: number | undefined; + + 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 < chartOverview[category].min) {