summaryrefslogtreecommitdiff
path: root/src/store/modules/Control/PowerConsumptionStore.js
blob: bdc97518a055b59b6dd1ae44517cf4acf5cf88f7 (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
import api from '../../api';

const PowerConsumptionStore = {
  namespaced: true,
  state: {
    powerConsumption: false
  },
  getters: {
    powerConsumption: state => state.powerConsumption
  },
  mutations: {
    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);
          commit('setPowerConsumption', powerConsumption);
        })
        .catch(error => {
          console.log('Power Consumption', error);
        });
    }
  }
};

export default PowerConsumptionStore;