Remove hardcoded chassis in Manage power usage

Simmilar modification to
https://gerrit.openbmc-project.xyz/c/openbmc/webui-vue/+/42988
which removes the hardcoded chassis name from url on Manage power usage
tab. With this modification we are displaying only informations about
first power device. This change also fixes the overwriting existing
power cap value on load.

Signed-off-by: MichalX Szopinski <michalx.szopinski@intel.com>
Change-Id: Ia164db9f2c50d98bc767c0f4729e9572a2d01da1
diff --git a/src/store/modules/ResourceManagement/PowerControlStore.js b/src/store/modules/ResourceManagement/PowerControlStore.js
index 9dbddf0..94c570f 100644
--- a/src/store/modules/ResourceManagement/PowerControlStore.js
+++ b/src/store/modules/ResourceManagement/PowerControlStore.js
@@ -5,15 +5,18 @@
   namespaced: true,
   state: {
     powerCapValue: null,
+    powerCapUri: '',
     powerConsumptionValue: null,
   },
   getters: {
     powerCapValue: (state) => state.powerCapValue,
+    powerCapUri: (state) => state.powerCapUri,
     powerConsumptionValue: (state) => state.powerConsumptionValue,
   },
   mutations: {
     setPowerCapValue: (state, powerCapValue) =>
       (state.powerCapValue = powerCapValue),
+    setPowerCapUri: (state, powerCapUri) => (state.powerCapUri = powerCapUri),
     setPowerConsumptionValue: (state, powerConsumptionValue) =>
       (state.powerConsumptionValue = powerConsumptionValue),
   },
@@ -21,15 +24,29 @@
     setPowerCapUpdatedValue({ commit }, value) {
       commit('setPowerCapValue', value);
     },
-    async getPowerControl({ commit }) {
+    async getChassisCollection() {
       return await api
-        .get('/redfish/v1/Chassis/chassis/Power')
+        .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 getPowerControl({ dispatch, commit }) {
+      const collection = await dispatch('getChassisCollection');
+      if (!collection || collection.length === 0) return;
+      return await api
+        .get(`${collection[0]}`)
+        .then((response) => api.get(response.data.Power['@odata.id']))
         .then((response) => {
           const powerControl = response.data.PowerControl;
+          if (!powerControl || powerControl.length === 0) return;
+          const powerCapUri = powerControl[0]['@odata.id'];
           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('setPowerCapUri', powerCapUri);
           commit('setPowerCapValue', powerCap);
           commit('setPowerConsumptionValue', powerConsumption);
         })
@@ -37,13 +54,12 @@
           console.log('Power control', error);
         });
     },
-    async setPowerControl(_, powerCapValue) {
+    async setPowerControl({ state }, powerCapValue) {
       const data = {
         PowerControl: [{ PowerLimit: { LimitInWatts: powerCapValue } }],
       };
-
       return await api
-        .patch('/redfish/v1/Chassis/chassis/Power', data)
+        .patch(state.powerCapUri, data)
         .then(() =>
           i18n.t('pageServerPowerOperations.toast.successSaveSettings')
         )