adapted SodistoreHome Battery View based on BatteryClusterNumber in frontend
This commit is contained in:
parent
947ffaa11c
commit
58bd0611a3
|
|
@ -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,52 +35,23 @@ 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),
|
||||||
? [
|
|
||||||
{
|
|
||||||
BatteryId: '1',
|
|
||||||
battery: {
|
battery: {
|
||||||
Voltage: inverter.Battery1Voltage,
|
Voltage: inverter[`Battery${index}Voltage`],
|
||||||
Current: inverter.Battery1Current,
|
Current: inverter[`Battery${index}Current`],
|
||||||
Power: inverter.Battery1Power,
|
Power: inverter[`Battery${index}Power`],
|
||||||
Soc: inverter.Battery1Soc,
|
Soc: inverter[`Battery${index}Soc`],
|
||||||
Soh: inverter.Battery1Soh,
|
Soh: inverter[`Battery${index}Soh`],
|
||||||
// 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);
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue