Move power control to redfish

Replaces power cap store and power consumption store with power control store
and uses redfish.

Signed-off-by: Dixsie Wolmers <dixsie@ibm.com>
Change-Id: I5cce223da17373bcae3e7c6736a4580e1bd8ae00
diff --git a/src/store/index.js b/src/store/index.js
index 8a444a6..6bad517 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -7,8 +7,7 @@
 import OverviewStore from './modules/Overview/OverviewStore';
 import FirmwareStore from './modules/Configuration/FirmwareStore';
 import ControlStore from './modules/Control/ControlStore';
-import PowerConsumptionStore from './modules/Control/PowerConsumptionStore';
-import PowerCapStore from './modules/Control/PowerCapStore';
+import PowerControlStore from './modules/Control/PowerControlStore';
 import NetworkSettingStore from './modules/Configuration/NetworkSettingsStore';
 import EventLogStore from './modules/Health/EventLogStore';
 
@@ -27,8 +26,7 @@
     overview: OverviewStore,
     firmware: FirmwareStore,
     controls: ControlStore,
-    powerConsumption: PowerConsumptionStore,
-    powerCap: PowerCapStore,
+    powerControl: PowerControlStore,
     networkSettings: NetworkSettingStore,
     eventLog: EventLogStore
   },
diff --git a/src/store/modules/Control/PowerCapStore.js b/src/store/modules/Control/PowerCapStore.js
deleted file mode 100644
index 45a06ad..0000000
--- a/src/store/modules/Control/PowerCapStore.js
+++ /dev/null
@@ -1,32 +0,0 @@
-import api from '../../api';
-
-const PowerCapStore = {
-  namespaced: true,
-  state: {
-    powerCapData: false
-  },
-  getters: {
-    powerCapData: state => state.powerCapData
-  },
-  mutations: {
-    setPowerCapData: (state, powerCapData) =>
-      (state.powerCapData = powerCapData)
-  },
-  actions: {
-    getPowerCapData({ commit }) {
-      api
-        .get('/xyz/openbmc_project/control/host0/power_cap')
-        .then(response => {
-          const powerCapData = response.data.data;
-          if (powerCapData.PowerCapEnable) {
-            commit('setPowerCapData', powerCapData.PowerCap);
-          }
-        })
-        .catch(error => {
-          console.log('Power cap error', error);
-        });
-    }
-  }
-};
-
-export default PowerCapStore;
diff --git a/src/store/modules/Control/PowerConsumptionStore.js b/src/store/modules/Control/PowerConsumptionStore.js
deleted file mode 100644
index bdc9751..0000000
--- a/src/store/modules/Control/PowerConsumptionStore.js
+++ /dev/null
@@ -1,32 +0,0 @@
-import api from '../../api';
-
-const PowerConsumptionStore = {
-  namespaced: true,
-  state: {
-    powerConsumption: false
-  },
-  getters: {
-    powerConsumption: state => state.powerConsumption
-  },
-  mutations: {
-    setPowerConsumption: (state, powerConsumption) =>
-      (state.powerConsumption = powerConsumption)
-  },
-  actions: {
-    getPowerData({ commit }) {
-      api
-        .get('/xyz/openbmc_project/sensors/power/total_power')
-        .then(response => {
-          const powerData = response.data.data;
-          let powerConsumption =
-            powerData.Value * Math.pow(10, powerData.Scale);
-          commit('setPowerConsumption', powerConsumption);
-        })
-        .catch(error => {
-          console.log('Power Consumption', error);
-        });
-    }
-  }
-};
-
-export default PowerConsumptionStore;
diff --git a/src/store/modules/Control/PowerControlStore.js b/src/store/modules/Control/PowerControlStore.js
new file mode 100644
index 0000000..63ede2d
--- /dev/null
+++ b/src/store/modules/Control/PowerControlStore.js
@@ -0,0 +1,39 @@
+import api from '../../api';
+
+const PowerControlStore = {
+  namespaced: true,
+  state: {
+    powerCapValue: null,
+    powerConsumptionValue: null
+  },
+  getters: {
+    powerCapValue: state => state.powerCapValue,
+    powerConsumptionValue: state => state.powerConsumptionValue
+  },
+  mutations: {
+    setPowerCapValue: (state, powerCapValue) =>
+      (state.powerCapValue = powerCapValue),
+    setPowerConsumptionValue: (state, powerConsumptionValue) =>
+      (state.powerConsumptionValue = powerConsumptionValue)
+  },
+  actions: {
+    getPowerControl({ commit }) {
+      api
+        .get('/redfish/v1/Chassis/chassis/Power')
+        .then(response => {
+          const powerControl = response.data.PowerControl;
+          const powerCap = powerControl[0].PowerLimit.LimitInWatts;
+          // If system is powered off, power consumption does not exist in the PowerControl
+          const powerConsumption = powerControl[0].PowerConsumedWatts || null;
+
+          commit('setPowerCapValue', powerCap);
+          commit('setPowerConsumptionValue', powerConsumption);
+        })
+        .catch(error => {
+          console.log('Power control', error);
+        });
+    }
+  }
+};
+
+export default PowerControlStore;
diff --git a/src/views/Overview/Overview.vue b/src/views/Overview/Overview.vue
index 76a062c..962d9a3 100644
--- a/src/views/Overview/Overview.vue
+++ b/src/views/Overview/Overview.vue
@@ -60,15 +60,19 @@
             <b-col sm="6">
               <dl>
                 <dt>{{ $t('pageOverview.powerConsumption') }}</dt>
-                <dd v-if="powerConsumption">{{ powerConsumption }} W</dd>
-                <dd v-else>{{ $t('global.status.notAvailable') }}</dd>
+                <dd v-if="powerConsumptionValue == null">
+                  {{ $t('global.status.notAvailable') }}
+                </dd>
+                <dd v-else>{{ powerConsumptionValue }} W</dd>
               </dl>
             </b-col>
             <b-col sm="6">
               <dl>
                 <dt>{{ $t('pageOverview.powerCap') }}</dt>
-                <dd v-if="powerCapData">{{ powerCapData }} W</dd>
-                <dd v-else>{{ $t('global.status.disabled') }}</dd>
+                <dd v-if="powerCapValue == null">
+                  {{ $t('global.status.disabled') }}
+                </dd>
+                <dd v-else>{{ powerCapValue }} W</dd>
               </dl>
             </b-col>
           </b-row>
@@ -103,10 +107,10 @@
     serverManufacturer: state => state.overview.serverManufacturer,
     serverSerialNumber: state => state.overview.serverSerialNumber,
     hostName: state => state.global.hostName,
-    hostFirmwareVersion: state => state.firmware.hostFirmwareVersion,
-    bmcFirmwareVersion: state => state.firmware.bmcFirmwareVersion,
-    powerConsumption: state => state.powerConsumption.powerConsumption,
-    powerCapValue: state => state.powerCap.powerCapValue
+    hostActiveVersion: state => state.firmware.hostActiveVersion,
+    bmcActiveVersion: state => state.firmware.bmcActiveVersion,
+    powerCapValue: state => state.powerControl.powerCapValue,
+    powerConsumptionValue: state => state.powerControl.powerConsumptionValue
   }),
   created() {
     this.getOverviewInfo();
@@ -115,10 +119,8 @@
     getOverviewInfo() {
       this.$store.dispatch('overview/getServerInfo');
       this.$store.dispatch('global/getHostName');
-      this.$store.dispatch('firmware/getBmcFirmware');
-      this.$store.dispatch('firmware/getHostFirmware');
-      this.$store.dispatch('powerConsumption/getPowerData');
-      this.$store.dispatch('powerCap/getPowerCapData');
+      this.$store.dispatch('firmware/getFirmwareInfo');
+      this.$store.dispatch('powerControl/getPowerControl');
     }
   }
 };