Fan data from Thermal or ThermalSubsystem API

Fan data API switch in Inventory and LEDs page based on
environment variable VUE_APP_FAN_DATA_FROM_THERMAL_SUBSYSTEM.

Backend Support PR:

https://gerrit.openbmc.org/c/openbmc/bmcweb/+/57533

Change-Id: I95ac9f9cef97bdab84a179b3e318eb37ab11752b
Signed-off-by: Sivaprabu Ganesan <sivaprabug@ami.com>
diff --git a/.env.intel b/.env.intel
index 6a8c181..c7dea36 100644
--- a/.env.intel
+++ b/.env.intel
@@ -8,6 +8,7 @@
 VUE_APP_VIRTUAL_MEDIA_LIST_ENABLED="true"
 VUE_APP_EVENT_LOGS_DELETE_BUTTON_DISABLED="true"
 VUE_APP_EVENT_LOGS_TOGGLE_BUTTON_DISABLED="true"
+VUE_APP_FAN_DATA_FROM_THERMAL_SUBSYSTEM="true"
 CUSTOM_STYLES="true"
 CUSTOM_APP_NAV="true"
 CUSTOM_STORE="true"
diff --git a/src/store/modules/HardwareStatus/FanStore.js b/src/store/modules/HardwareStatus/FanStore.js
index 3f172d2..832ef63 100644
--- a/src/store/modules/HardwareStatus/FanStore.js
+++ b/src/store/modules/HardwareStatus/FanStore.js
@@ -11,29 +11,49 @@
   mutations: {
     setFanInfo: (state, data) => {
       state.fans = data.map((fan) => {
-        const {
-          IndicatorLED,
-          Location,
-          MemberId,
-          Name,
-          Reading,
-          ReadingUnits,
-          Status = {},
-          PartNumber,
-          SerialNumber,
-        } = fan;
-        return {
-          id: MemberId,
-          health: Status.Health,
-          partNumber: PartNumber,
-          serialNumber: SerialNumber,
-          healthRollup: Status.HealthRollup,
-          identifyLed: IndicatorLED,
-          locationNumber: Location,
-          name: Name,
-          speed: Reading + ' ' + ReadingUnits,
-          statusState: Status.State,
-        };
+        const ThermalSubsystem =
+          process.env.VUE_APP_FAN_DATA_FROM_THERMAL_SUBSYSTEM === 'true'
+            ? true
+            : false;
+        if (ThermalSubsystem) {
+          const {
+            Id,
+            Name,
+            PartNumber,
+            SerialNumber,
+            SpeedPercent = {},
+            Status = {},
+          } = fan;
+          return {
+            id: Id,
+            health: Status.Health,
+            name: Name,
+            speed: SpeedPercent.Reading,
+            statusState: Status.State,
+            healthRollup: Status.HealthRollup,
+            partNumber: PartNumber,
+            serialNumber: SerialNumber,
+          };
+        } else {
+          const {
+            MemberId,
+            Name,
+            Reading,
+            Status = {},
+            PartNumber,
+            SerialNumber,
+          } = fan;
+          return {
+            id: MemberId,
+            health: Status.Health,
+            partNumber: PartNumber,
+            serialNumber: SerialNumber,
+            healthRollup: Status.HealthRollup,
+            name: Name,
+            speed: Reading,
+            statusState: Status.State,
+          };
+        }
       });
     },
   },
@@ -59,10 +79,35 @@
         .catch((error) => console.log(error));
     },
     async getChassisFans(_, chassis) {
-      return await api
-        .get(chassis.Thermal['@odata.id'])
-        .then(({ data: { Fans } }) => Fans || [])
-        .catch((error) => console.log(error));
+      const ThermalSubsystem =
+        process.env.VUE_APP_FAN_DATA_FROM_THERMAL_SUBSYSTEM === 'true'
+          ? true
+          : false;
+      if (ThermalSubsystem) {
+        return await api
+          .get(chassis.ThermalSubsystem['@odata.id'])
+          .then((response) => {
+            return api.get(`${response.data.Fans['@odata.id']}`);
+          })
+          .then(({ data: { Members } }) => {
+            const promises = Members.map((member) =>
+              api.get(member['@odata.id'])
+            );
+            return api.all(promises);
+          })
+          .then((response) => {
+            const data = response.map(({ data }) => data);
+            return data;
+          })
+          .catch((error) => console.log(error));
+      } else {
+        return await api
+          .get(chassis.Thermal['@odata.id'])
+          .then(({ data: { Fans } }) => {
+            return Fans || [];
+          })
+          .catch((error) => console.log(error));
+      }
     },
   },
 };