Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 3, 2024
1 parent 2149a7b commit 8ac7906
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions ui/src/store/slices/SystemStatus.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import { createSlice } from '@reduxjs/toolkit';

function preprocessSystemStatus(systemStatus) {
if(null == systemStatus) return null;
// convert "water threshold" to "waterThreshold"
systemStatus.waterThreshold = systemStatus["water threshold"];
delete systemStatus["water threshold"];

// convert "time left" to "timeLeft"
systemStatus.pump.timeLeft = systemStatus.pump["time left"];
delete systemStatus.pump["time left"];

// add field "updated"
systemStatus.updated = Date.now();
return systemStatus;
}
// TODO: Replace this with a real system status
// replace "water threshold" with "waterThreshold"
// replace "time left" with "timeLeft"
// add field "updated"
const systemStatus = {
waterThreshold: 1234,
pump: {
running: false,
timeLeft: 0,
},
updated: Date.now(),
};
const systemStatus = preprocessSystemStatus({
"water threshold": 1234,
"pump": {
"running": false,
"time left": 0
}
});

// slice for system status
export const SystemStatusSlice = createSlice({
name: 'systemStatus',
initialState: systemStatus,
reducers: {
updateSystemStatus(state, action) {
return action.payload;
return preprocessSystemStatus(action.payload);
},
},
});
Expand Down

0 comments on commit 8ac7906

Please sign in to comment.