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

View File

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