xref: /openbmc/webui-vue/src/store/modules/HardwareStatus/PowerSupplyStore.js (revision 59a732bc502740ee5d7ea37298a9576fb4131858)
17affc529SSandeepa Singhimport api from '@/store/api';
27affc529SSandeepa Singh
37affc529SSandeepa Singhconst PowerSupplyStore = {
47affc529SSandeepa Singh  namespaced: true,
57affc529SSandeepa Singh  state: {
67affc529SSandeepa Singh    powerSupplies: [],
77affc529SSandeepa Singh  },
87affc529SSandeepa Singh  getters: {
97affc529SSandeepa Singh    powerSupplies: (state) => state.powerSupplies,
107affc529SSandeepa Singh  },
117affc529SSandeepa Singh  mutations: {
127affc529SSandeepa Singh    setPowerSupply: (state, data) => {
137affc529SSandeepa Singh      state.powerSupplies = data.map((powerSupply) => {
147affc529SSandeepa Singh        const {
15*59a732bcSHuyLe          EfficiencyRatings = [],
167affc529SSandeepa Singh          FirmwareVersion,
177affc529SSandeepa Singh          LocationIndicatorActive,
18*59a732bcSHuyLe          Id,
197affc529SSandeepa Singh          Manufacturer,
207affc529SSandeepa Singh          Model,
217affc529SSandeepa Singh          Name,
227affc529SSandeepa Singh          PartNumber,
237affc529SSandeepa Singh          PowerInputWatts,
247affc529SSandeepa Singh          SerialNumber,
257affc529SSandeepa Singh          SparePartNumber,
269f61234aSSneha Patel          Location,
277affc529SSandeepa Singh          Status = {},
287affc529SSandeepa Singh        } = powerSupply;
297affc529SSandeepa Singh        return {
30*59a732bcSHuyLe          id: Id,
317affc529SSandeepa Singh          health: Status.Health,
327affc529SSandeepa Singh          partNumber: PartNumber,
337affc529SSandeepa Singh          serialNumber: SerialNumber,
34*59a732bcSHuyLe          efficiencyPercent: EfficiencyRatings[0].EfficiencyPercent,
357affc529SSandeepa Singh          firmwareVersion: FirmwareVersion,
367affc529SSandeepa Singh          identifyLed: LocationIndicatorActive,
377affc529SSandeepa Singh          manufacturer: Manufacturer,
387affc529SSandeepa Singh          model: Model,
397affc529SSandeepa Singh          powerInputWatts: PowerInputWatts,
407affc529SSandeepa Singh          name: Name,
417affc529SSandeepa Singh          sparePartNumber: SparePartNumber,
429f61234aSSneha Patel          locationNumber: Location?.PartLocation?.ServiceLabel,
437affc529SSandeepa Singh          statusState: Status.State,
447affc529SSandeepa Singh        };
457affc529SSandeepa Singh      });
467affc529SSandeepa Singh    },
477affc529SSandeepa Singh  },
487affc529SSandeepa Singh  actions: {
497affc529SSandeepa Singh    async getChassisCollection() {
507affc529SSandeepa Singh      return await api
517affc529SSandeepa Singh        .get('/redfish/v1/Chassis')
527affc529SSandeepa Singh        .then(({ data: { Members } }) =>
538132399cSEd Tanous          Members.map((member) => member['@odata.id']),
547affc529SSandeepa Singh        )
557affc529SSandeepa Singh        .catch((error) => console.log(error));
567affc529SSandeepa Singh    },
577affc529SSandeepa Singh    async getAllPowerSupplies({ dispatch, commit }) {
587affc529SSandeepa Singh      const collection = await dispatch('getChassisCollection');
597affc529SSandeepa Singh      if (!collection) return;
607affc529SSandeepa Singh      return await api
617affc529SSandeepa Singh        .all(collection.map((chassis) => dispatch('getChassisPower', chassis)))
627affc529SSandeepa Singh        .then((supplies) => {
637affc529SSandeepa Singh          let suppliesList = [];
647affc529SSandeepa Singh          supplies.forEach(
658132399cSEd Tanous            (supply) => (suppliesList = [...suppliesList, ...supply]),
667affc529SSandeepa Singh          );
677affc529SSandeepa Singh          commit('setPowerSupply', suppliesList);
687affc529SSandeepa Singh        })
697affc529SSandeepa Singh        .catch((error) => console.log(error));
707affc529SSandeepa Singh    },
717affc529SSandeepa Singh    async getChassisPower(_, id) {
727affc529SSandeepa Singh      return await api
73*59a732bcSHuyLe        .get(`${id}/PowerSubsystem`)
74*59a732bcSHuyLe        .then((response) => {
75*59a732bcSHuyLe          return api.get(`${response.data.PowerSupplies['@odata.id']}`);
76*59a732bcSHuyLe        })
77*59a732bcSHuyLe        .then(({ data: { Members } }) => {
78*59a732bcSHuyLe          const promises = Members.map((member) =>
79*59a732bcSHuyLe            api.get(member['@odata.id']),
80*59a732bcSHuyLe          );
81*59a732bcSHuyLe          return api.all(promises);
82*59a732bcSHuyLe        })
83*59a732bcSHuyLe        .then((response) => {
84*59a732bcSHuyLe          const data = response.map(({ data }) => data);
85*59a732bcSHuyLe          return data;
86*59a732bcSHuyLe        })
877affc529SSandeepa Singh        .catch((error) => console.log(error));
887affc529SSandeepa Singh    },
897affc529SSandeepa Singh  },
907affc529SSandeepa Singh};
917affc529SSandeepa Singh
927affc529SSandeepa Singhexport default PowerSupplyStore;
93