blob: 785853955dc768d34b389cb8ec1676ab50851aff [file] [log] [blame]
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -06001import api from '../../api';
2
3const PowerControlStore = {
4 namespaced: true,
5 state: {
6 powerCapValue: null,
7 powerConsumptionValue: null
8 },
9 getters: {
10 powerCapValue: state => state.powerCapValue,
11 powerConsumptionValue: state => state.powerConsumptionValue
12 },
13 mutations: {
14 setPowerCapValue: (state, powerCapValue) =>
15 (state.powerCapValue = powerCapValue),
16 setPowerConsumptionValue: (state, powerConsumptionValue) =>
17 (state.powerConsumptionValue = powerConsumptionValue)
18 },
19 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070020 async getPowerControl({ commit }) {
21 return await api
Dixsie Wolmers4c69f5b2020-02-26 11:23:52 -060022 .get('/redfish/v1/Chassis/chassis/Power')
23 .then(response => {
24 const powerControl = response.data.PowerControl;
25 const powerCap = powerControl[0].PowerLimit.LimitInWatts;
26 // If system is powered off, power consumption does not exist in the PowerControl
27 const powerConsumption = powerControl[0].PowerConsumedWatts || null;
28
29 commit('setPowerCapValue', powerCap);
30 commit('setPowerConsumptionValue', powerConsumption);
31 })
32 .catch(error => {
33 console.log('Power control', error);
34 });
35 }
36 }
37};
38
39export default PowerControlStore;