Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
| 3 | const PowerConsumptionStore = { |
| 4 | namespaced: true, |
| 5 | state: { |
| 6 | powerData: null, |
| 7 | powerConsumption: 'Not available' |
| 8 | }, |
| 9 | getters: { |
| 10 | powerData: state => state.powerData, |
| 11 | powerConsumption: state => state.powerConsumption |
| 12 | }, |
| 13 | mutations: { |
| 14 | setPowerData: (state, powerData) => (state.powerData = powerData), |
| 15 | setPowerConsumption: (state, powerConsumption) => |
| 16 | (state.powerConsumption = powerConsumption) |
| 17 | }, |
| 18 | actions: { |
| 19 | getPowerData({ commit }) { |
| 20 | api |
| 21 | .get('/xyz/openbmc_project/sensors/power/total_power') |
| 22 | .then(response => { |
| 23 | const powerData = response.data.data; |
| 24 | let powerConsumption = |
| 25 | powerData.Value * Math.pow(10, powerData.Scale) + ' W'; |
| 26 | commit('setPowerConsumption', powerConsumption); |
| 27 | }) |
| 28 | .catch(error => { |
| 29 | console.log('Power Consumption', error); |
| 30 | }); |
| 31 | } |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | export default PowerConsumptionStore; |