diff --git a/ui/src/store/slices/SystemStatus.js b/ui/src/store/slices/SystemStatus.js index 86b047e..5c12a49 100644 --- a/ui/src/store/slices/SystemStatus.js +++ b/ui/src/store/slices/SystemStatus.js @@ -1,17 +1,27 @@ 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({ @@ -19,7 +29,7 @@ export const SystemStatusSlice = createSlice({ initialState: systemStatus, reducers: { updateSystemStatus(state, action) { - return action.payload; + return preprocessSystemStatus(action.payload); }, }, });