From ce69dc38e39aaeb0b531842970da9784093861f8 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Fri, 1 Jul 2022 15:43:26 +0300 Subject: show only fans items --- src/store/modules/HardwareStatus/SensorsStore.js | 42 ++++++++++++++++++++++ .../Fans/StaticInformation/FansStaticPage.vue | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/store/modules/HardwareStatus/SensorsStore.js b/src/store/modules/HardwareStatus/SensorsStore.js index 287796d9..f28c50ea 100644 --- a/src/store/modules/HardwareStatus/SensorsStore.js +++ b/src/store/modules/HardwareStatus/SensorsStore.js @@ -26,6 +26,15 @@ const SensorsStore = { }, []); return await api.all(promises); }, + async getFanSensors({ dispatch }) { + const collection = await dispatch('getChassisCollection'); + if (!collection) return; + const promises = collection.reduce((acc, id) => { + acc.push(dispatch('getOnlyFanSensors', id)); + return acc; + }, []); + return await api.all(promises); + }, async getChassisCollection() { return await api .get('/redfish/v1/Chassis') @@ -64,6 +73,39 @@ const SensorsStore = { }) ); }, + async getOnlyFanSensors({ commit }, id) { + const sensors = await api + .get(`${id}/Sensors`) + .then((response) => response.data.Members) + .catch((error) => console.log(error)); + const fanSensors = sensors.filter((sensor) => { + return sensor['@odata.id'].toLowerCase().includes('fan'); + }); + if (!fanSensors) return; + const promises = fanSensors.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, + lowerCaution: data.Thresholds?.LowerCaution?.Reading, + upperCaution: data.Thresholds?.UpperCaution?.Reading, + lowerCritical: data.Thresholds?.LowerCritical?.Reading, + upperCritical: data.Thresholds?.UpperCritical?.Reading, + units: data.ReadingUnits, + }; + }); + commit('setSensors', sensorData); + }) + ); + }, async getThermalSensors({ commit }, id) { return await api .get(`${id}/Thermal`) diff --git a/src/views/Fans/StaticInformation/FansStaticPage.vue b/src/views/Fans/StaticInformation/FansStaticPage.vue index 6b071e87..ba312384 100644 --- a/src/views/Fans/StaticInformation/FansStaticPage.vue +++ b/src/views/Fans/StaticInformation/FansStaticPage.vue @@ -124,7 +124,7 @@ export default { }, created() { - this.$store.dispatch('sensors/getAllSensors').finally(() => { + this.$store.dispatch('sensors/getFanSensors').finally(() => { this.isBusy = false; }); }, -- cgit v1.2.3