blob: 03ccffceb4cb1031c175a7afd3b347eef9b9d5aa [file] [log] [blame]
import api from '../../api';
const PowerConsumptionStore = {
namespaced: true,
state: {
powerData: null,
powerConsumption: 'Not available'
},
getters: {
powerData: state => state.powerData,
powerConsumption: state => state.powerConsumption
},
mutations: {
setPowerData: (state, powerData) => (state.powerData = powerData),
setPowerConsumption: (state, powerConsumption) =>
(state.powerConsumption = powerConsumption)
},
actions: {
getPowerData({ commit }) {
api
.get('/xyz/openbmc_project/sensors/power/total_power')
.then(response => {
const powerData = response.data.data;
let powerConsumption =
powerData.Value * Math.pow(10, powerData.Scale) + ' W';
commit('setPowerConsumption', powerConsumption);
})
.catch(error => {
console.log('Power Consumption', error);
});
}
}
};
export default PowerConsumptionStore;