summaryrefslogtreecommitdiff
path: root/src/store/modules/Control/PowerControlStore.js
blob: 63ede2d445a24576f27aa640c6a3d9280e3b46d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;