summaryrefslogtreecommitdiff
path: root/src/store/modules/HardwareStatus/SensorsStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/store/modules/HardwareStatus/SensorsStore.js')
-rw-r--r--src/store/modules/HardwareStatus/SensorsStore.js46
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`)