adapted SodistoreHome Battery View based on BatteryClusterNumber in frontend

This commit is contained in:
Yinyin Liu 2025-11-17 12:54:29 +01:00
parent 947ffaa11c
commit 58bd0611a3
2 changed files with 18 additions and 44 deletions

View File

@ -18,11 +18,13 @@ import { FormattedMessage } from 'react-intl';
import { I_S3Credentials } from '../../../interfaces/S3Types';
import routes from '../../../Resources/routes.json';
import CircularProgress from '@mui/material/CircularProgress';
import { I_Installation } from 'src/interfaces/InstallationTypes';
interface BatteryViewSodioHomeProps {
values: JSONRecordData;
s3Credentials: I_S3Credentials;
installationId: number;
installation: I_Installation;
connected: boolean;
}
@ -33,53 +35,24 @@ function BatteryViewSodioHome(props: BatteryViewSodioHomeProps) {
const currentLocation = useLocation();
const navigate = useNavigate();
// const sortedBatteryView =
// props.values != null &&
// props.values?.AcDcGrowatt?.BatteriesRecords?.Batteries
// ? Object.entries(props.values.AcDcGrowatt.BatteriesRecords.Batteries)
// .map(([BatteryId, battery]) => {
// return { BatteryId, battery }; // Here we return an object with the id and device
// })
// .sort((a, b) => parseInt(b.BatteryId) - parseInt(a.BatteryId))
// : [];
const inverter = (props.values as any)?.InverterRecord;
const batteryClusterNumber = props.installation.batteryClusterNumber;
const sortedBatteryView = inverter
? Array.from({ length: batteryClusterNumber }, (_, i) => {
const index = i + 1; // Battery1, Battery2, ...
const sortedBatteryView =
inverter
? [
{
BatteryId: '1',
battery: {
Voltage: inverter.Battery1Voltage,
Current: inverter.Battery1Current,
Power: inverter.Battery1Power,
Soc: inverter.Battery1Soc,
Soh: inverter.Battery1Soh,
// DailyDischargeEnergy: inverter.Battery1DailyDischargeEnergy,
// DailyChargeEnergy: inverter.Battery1DailyChargeEnergy,
}
},
{
BatteryId: '2',
battery: {
Voltage: inverter.Battery2Voltage,
Current: inverter.Battery2Current,
Power: inverter.Battery2Power,
Soc: inverter.Battery2Soc,
Soh: inverter.Battery2Soh,
// DailyDischargeEnergy: inverter.Battery2DailyDischargeEnergy,
// DailyChargeEnergy: inverter.Battery2DailyChargeEnergy,
}
return {
BatteryId: String(index),
battery: {
Voltage: inverter[`Battery${index}Voltage`],
Current: inverter[`Battery${index}Current`],
Power: inverter[`Battery${index}Power`],
Soc: inverter[`Battery${index}Soc`],
Soh: inverter[`Battery${index}Soh`],
}
]// filter out batteries where all numeric values are 0 or null/undefined
.filter(({ battery }) =>
Object.values(battery).some(
(v) => typeof v === 'number' && v !== 0
)
)
: [];
};
})
: [];
const [loading, setLoading] = useState(sortedBatteryView.length == 0);
const handleMainStatsButton = () => {

View File

@ -481,6 +481,7 @@ function SodioHomeInstallation(props: singleInstallationProps) {
values={values}
s3Credentials={s3Credentials}
installationId={props.current_installation.id}
installation={props.current_installation}
connected={connected}
></BatteryViewSodioHome>
}