Update firmware on frontend

This commit is contained in:
Noe 2024-03-19 17:42:52 +01:00
parent 2f24f97304
commit ce12d6a59a
2 changed files with 64 additions and 42 deletions

View File

@ -35,7 +35,13 @@ function Configuration(props: ConfigurationProps) {
return null; return null;
} }
const forcedCalibrationChargeOptions = [ const CalibrationChargeOptions = [
'Repetitive Calibration',
'Additional Calibration',
'Force Calibration Now'
];
const CalibrationChargeOptionsController = [
'RepetitivelyEvery', 'RepetitivelyEvery',
'AdditionallyOnce', 'AdditionallyOnce',
'ChargePermanently' 'ChargePermanently'
@ -64,18 +70,41 @@ function Configuration(props: ConfigurationProps) {
selectedForcedCalibrationChargeOption, selectedForcedCalibrationChargeOption,
setSelectedForcedCalibrationChargeOption setSelectedForcedCalibrationChargeOption
] = useState<string>( ] = useState<string>(
props.values.calibrationChargeForced[0].value.toString() CalibrationChargeOptions[
CalibrationChargeOptionsController.indexOf(
props.values.calibrationChargeState[0].value.toString()
)
]
); );
const [formValues, setFormValues] = useState<ConfigurationValues>({ const [formValues, setFormValues] = useState<ConfigurationValues>({
minimumSoC: props.values.minimumSoC[0].value, minimumSoC: props.values.minimumSoC[0].value,
gridSetPoint: (props.values.gridSetPoint[0].value as number) / 1000, gridSetPoint: (props.values.gridSetPoint[0].value as number) / 1000,
forceCalibrationCharge: forcedCalibrationChargeOptions.indexOf( CalibrationChargeState: CalibrationChargeOptionsController.indexOf(
props.values.calibrationChargeForced[0].value.toString() props.values.calibrationChargeState[0].value.toString()
), ),
calibrationChargeDate: null calibrationChargeDate:
CalibrationChargeOptionsController.indexOf(
props.values.calibrationChargeState[0].value.toString()
) == 0
? dayjs(props.values.repetitiveCalibrationChargeDate[0].value).toDate()
: dayjs(props.values.additionalCalibrationChargeDate[0].value).toDate()
}); });
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
if (
props.values.mode[0].value === 'CalibrationCharge' &&
formValues.CalibrationChargeState == 0
) {
setDateSelectionError(
'You cannot change the date while the installation is in Calibration Charge Mode'
);
setErrorDateModalOpen(true);
return;
} else if (dayjs(formValues.calibrationChargeDate).isBefore(dayjs())) {
setDateSelectionError('You must specify a future date');
setErrorDateModalOpen(true);
return;
} else {
setLoading(true); setLoading(true);
const res = await axiosConfig const res = await axiosConfig
.post(`/EditInstallationConfig?installationId=${props.id}`, formValues) .post(`/EditInstallationConfig?installationId=${props.id}`, formValues)
@ -90,6 +119,7 @@ function Configuration(props: ConfigurationProps) {
setUpdated(true); setUpdated(true);
setLoading(false); setLoading(false);
} }
}
}; };
const handleOkOnErrorDateModal = () => { const handleOkOnErrorDateModal = () => {
@ -97,12 +127,6 @@ function Configuration(props: ConfigurationProps) {
}; };
const handleConfirm = (newDate) => { const handleConfirm = (newDate) => {
if (newDate.isBefore(dayjs())) {
setDateSelectionError('You must specify a future date');
setErrorDateModalOpen(true);
return;
}
setFormValues({ setFormValues({
...formValues, ...formValues,
['calibrationChargeDate']: newDate.toDate() ['calibrationChargeDate']: newDate.toDate()
@ -114,9 +138,17 @@ function Configuration(props: ConfigurationProps) {
setFormValues({ setFormValues({
...formValues, ...formValues,
['forceCalibrationCharge']: forcedCalibrationChargeOptions.indexOf( ['CalibrationChargeState']: CalibrationChargeOptions.indexOf(
event.target.value event.target.value
) ),
['calibrationChargeDate']:
CalibrationChargeOptions.indexOf(event.target.value) == 0
? dayjs(
props.values.repetitiveCalibrationChargeDate[0].value
).toDate()
: dayjs(
props.values.additionalCalibrationChargeDate[0].value
).toDate()
}); });
}; };
@ -258,7 +290,7 @@ function Configuration(props: ConfigurationProps) {
> >
<FormattedMessage <FormattedMessage
id="forced_calibration_charge" id="forced_calibration_charge"
defaultMessage="Forced Calibration Charge" defaultMessage="Calibration Charge State"
/> />
</InputLabel> </InputLabel>
<Select <Select
@ -268,7 +300,7 @@ function Configuration(props: ConfigurationProps) {
onClose={handleCloseForcedCalibrationCharge} onClose={handleCloseForcedCalibrationCharge}
onOpen={handleOpenForcedCalibrationCharge} onOpen={handleOpenForcedCalibrationCharge}
> >
{forcedCalibrationChargeOptions.map((option) => ( {CalibrationChargeOptions.map((option) => (
<MenuItem key={option} value={option}> <MenuItem key={option} value={option}>
{option} {option}
</MenuItem> </MenuItem>
@ -276,22 +308,12 @@ function Configuration(props: ConfigurationProps) {
</Select> </Select>
</FormControl> </FormControl>
</div> </div>
{formValues.forceCalibrationCharge != 2 && ( {formValues.CalibrationChargeState != 2 && (
<div> <div>
<LocalizationProvider dateAdapter={AdapterDayjs}> <LocalizationProvider dateAdapter={AdapterDayjs}>
<DateTimePicker <DateTimePicker
label="Select Next Calibration Charge Date" label="Select Next Calibration Charge Date"
value={ value={dayjs(formValues.calibrationChargeDate)}
formValues.forceCalibrationCharge == 0
? dayjs(
props.values.repetitiveCalibrationChargeDate[0]
.value
)
: dayjs(
props.values.additionalCalibrationChargeDate[0]
.value
)
}
onChange={handleConfirm} onChange={handleConfirm}
sx={{ sx={{
marginTop: 2 marginTop: 2

View File

@ -31,7 +31,7 @@ export interface I_BoxDataValue {
export type ConfigurationValues = { export type ConfigurationValues = {
minimumSoC: string | number; minimumSoC: string | number;
gridSetPoint: number; gridSetPoint: number;
forceCalibrationCharge: number; CalibrationChargeState: number;
calibrationChargeDate: Date | null; calibrationChargeDate: Date | null;
}; };
@ -157,7 +157,7 @@ export type TopologyValues = {
gridSetPoint: I_BoxDataValue[]; gridSetPoint: I_BoxDataValue[];
maximumDischargePower: I_BoxDataValue[]; maximumDischargePower: I_BoxDataValue[];
DcDcNum: I_BoxDataValue[]; DcDcNum: I_BoxDataValue[];
calibrationChargeForced: I_BoxDataValue[]; calibrationChargeState: I_BoxDataValue[];
mode: I_BoxDataValue[]; mode: I_BoxDataValue[];
repetitiveCalibrationChargeDate: I_BoxDataValue[]; repetitiveCalibrationChargeDate: I_BoxDataValue[];
additionalCalibrationChargeDate: I_BoxDataValue[]; additionalCalibrationChargeDate: I_BoxDataValue[];
@ -296,7 +296,7 @@ export const topologyPaths: TopologyPaths = {
gridSetPoint: ['/Config/GridSetPoint'], gridSetPoint: ['/Config/GridSetPoint'],
maximumDischargePower: ['/Config/MaxBatteryDischargingCurrent'], maximumDischargePower: ['/Config/MaxBatteryDischargingCurrent'],
DcDcNum: ['/DcDc/SystemControl/NumberOfConnectedSlaves'], DcDcNum: ['/DcDc/SystemControl/NumberOfConnectedSlaves'],
calibrationChargeForced: ['/Config/ForceCalibrationChargeState'], calibrationChargeState: ['/Config/ForceCalibrationChargeState'],
mode: ['/EssControl/Mode'], mode: ['/EssControl/Mode'],
repetitiveCalibrationChargeDate: [ repetitiveCalibrationChargeDate: [
'/Config/DayAndTimeForRepetitiveCalibration' '/Config/DayAndTimeForRepetitiveCalibration'