From fad8a1bc44c87d7ec451ab32f6fb94bf3a306e46 Mon Sep 17 00:00:00 2001 From: Dixsie Wolmers Date: Wed, 1 Sep 2021 08:27:55 -0500 Subject: [PATCH] Move sensors to use sensor collection schema (#7) Before to get all the Sensors 3 of a chassis, 3 calls were made: /redfish/v1/Chassis/{chassis}/Power /redfish/v1/Chassis/{chassis}/Thermal /redfish/v1/Chassis/{chassis}/Sensors With this change: https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/40169 All that is needed is a call to /redfish/v1/Chassis/{chassis}/Sensors Note: The threshold property is optional on some sensors, Optional chaining operator (?.) is used to return undefined if a property does not exist. Signed-off-by: Dixsie Wolmers --- .../modules/HardwareStatus/SensorsStore.js | 21 +++--- src/views/HardwareStatus/Sensors/Sensors.vue | 71 +++++++++++++------ 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/store/modules/HardwareStatus/SensorsStore.js b/src/store/modules/HardwareStatus/SensorsStore.js index 287796d9f3..50678cdf83 100644 --- a/src/store/modules/HardwareStatus/SensorsStore.js +++ b/src/store/modules/HardwareStatus/SensorsStore.js @@ -15,25 +15,22 @@ const SensorsStore = { }, }, actions: { - async getAllSensors({ dispatch }) { - const collection = await dispatch('getChassisCollection'); - if (!collection) return; - const promises = collection.reduce((acc, id) => { - acc.push(dispatch('getSensors', id)); - acc.push(dispatch('getThermalSensors', id)); - acc.push(dispatch('getPowerSensors', id)); - return acc; - }, []); - return await api.all(promises); - }, async getChassisCollection() { return await api - .get('/redfish/v1/Chassis') + .get('/redfish/v1/') + .then((response) => api.get(response.data.Chassis['@odata.id'])) .then(({ data: { Members } }) => Members.map((member) => member['@odata.id']) ) .catch((error) => console.log(error)); }, + async getAllSensors({ dispatch }) { + const collection = await dispatch('getChassisCollection'); + if (!collection) return; + return await api + .all(collection.map((chassis) => dispatch('getSensors', chassis))) + .catch((error) => console.log(error)); + }, async getSensors({ commit }, id) { const sensors = await api .get(`${id}/Sensors`) diff --git a/src/views/HardwareStatus/Sensors/Sensors.vue b/src/views/HardwareStatus/Sensors/Sensors.vue index 6329d9d8b8..0332befdf1 100644 --- a/src/views/HardwareStatus/Sensors/Sensors.vue +++ b/src/views/HardwareStatus/Sensors/Sensors.vue @@ -1,6 +1,15 @@