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 { I_S3Credentials } from '../../../interfaces/S3Types';
import routes from '../../../Resources/routes.json'; import routes from '../../../Resources/routes.json';
import CircularProgress from '@mui/material/CircularProgress'; import CircularProgress from '@mui/material/CircularProgress';
import { I_Installation } from 'src/interfaces/InstallationTypes';
interface BatteryViewSodioHomeProps { interface BatteryViewSodioHomeProps {
values: JSONRecordData; values: JSONRecordData;
s3Credentials: I_S3Credentials; s3Credentials: I_S3Credentials;
installationId: number; installationId: number;
installation: I_Installation;
connected: boolean; connected: boolean;
} }
@ -33,53 +35,24 @@ function BatteryViewSodioHome(props: BatteryViewSodioHomeProps) {
const currentLocation = useLocation(); const currentLocation = useLocation();
const navigate = useNavigate(); 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 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 = return {
inverter BatteryId: String(index),
? [ battery: {
{ Voltage: inverter[`Battery${index}Voltage`],
BatteryId: '1', Current: inverter[`Battery${index}Current`],
battery: { Power: inverter[`Battery${index}Power`],
Voltage: inverter.Battery1Voltage, Soc: inverter[`Battery${index}Soc`],
Current: inverter.Battery1Current, Soh: inverter[`Battery${index}Soh`],
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,
}
} }
]// 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 [loading, setLoading] = useState(sortedBatteryView.length == 0);
const handleMainStatsButton = () => { const handleMainStatsButton = () => {

View File

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