Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
| 3 | const 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 Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 20 | async getPowerControl({ commit }) { |
| 21 | return await api |
Dixsie Wolmers | 4c69f5b | 2020-02-26 11:23:52 -0600 | [diff] [blame] | 22 | .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 | |
| 39 | export default PowerControlStore; |