diff options
author | Vitalii Lysak <v.lysak@dunice.net> | 2022-07-06 10:59:45 +0300 |
---|---|---|
committer | Vitalii Lysak <v.lysak@dunice.net> | 2022-07-06 10:59:45 +0300 |
commit | 257b9b29b1c5ffb608b015bd780d1491de99bff6 (patch) | |
tree | 9a6fda42c529f62103156828ff6c519161842e5d /src/store/modules | |
parent | da090728003de7cf409d9df97b6bbbd5e672b444 (diff) | |
download | webui-vue-257b9b29b1c5ffb608b015bd780d1491de99bff6.tar.xz |
add dynamic info for motherboard
Diffstat (limited to 'src/store/modules')
-rw-r--r-- | src/store/modules/HardwareStatus/SensorsStore.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/store/modules/HardwareStatus/SensorsStore.js b/src/store/modules/HardwareStatus/SensorsStore.js index 896297e3..59872718 100644 --- a/src/store/modules/HardwareStatus/SensorsStore.js +++ b/src/store/modules/HardwareStatus/SensorsStore.js @@ -6,10 +6,12 @@ const SensorsStore = { state: { sensors: [], fanSensors: [], + tempSensors: [], }, getters: { sensors: (state) => state.sensors, fanSensors: (state) => state.fanSensors, + tempSensors: (state) => state.tempSensors, }, mutations: { setSensors: (state, sensors) => { @@ -18,6 +20,12 @@ const SensorsStore = { setFanSensors: (state, fanSensors) => { state.fanSensors = uniqBy([...state.fanSensors, ...fanSensors], 'name'); }, + setTempSensors: (state, tempSensors) => { + state.tempSensors = uniqBy( + [...state.tempSensors, ...tempSensors], + 'name' + ); + }, }, actions: { async getAllSensors({ dispatch }) { @@ -31,6 +39,15 @@ const SensorsStore = { }, []); return await api.all(promises); }, + async getTempSensors({ dispatch }) { + const collection = await dispatch('getChassisCollection'); + if (!collection) return; + const promises = collection.reduce((acc, id) => { + acc.push(dispatch('getOnlyTempSensors', id)); + return acc; + }, []); + return await api.all(promises); + }, async getFanSensors({ dispatch }) { const collection = await dispatch('getChassisCollection'); if (!collection) return; @@ -78,6 +95,35 @@ const SensorsStore = { }) ); }, + async getOnlyTempSensors({ commit }, id) { + const sensors = await api + .get(`${id}/Sensors`) + .then((response) => response.data.Members) + .catch((error) => console.log(error)); + const tempSensors = sensors.filter((sensor) => { + return sensor['@odata.id'].toLowerCase().includes('temp'); + }); + if (!tempSensors) return; + const promises = tempSensors.map((sensor) => { + return api.get(sensor['@odata.id']).catch((error) => { + console.log(error); + return error; + }); + }); + return await api.all(promises).then( + api.spread((...responses) => { + const sensorData = responses.map(({ data }) => { + return { + name: data.Name, + status: data.Status.Health, + currentValue: data.Reading, + units: data.ReadingUnits, + }; + }); + commit('setTempSensors', sensorData); + }) + ); + }, async getOnlyFanSensors({ commit }, id) { const sensors = await api .get(`${id}/Sensors`) |