import api from '@/store/api'; import i18n from '@/i18n'; const FanStore = { namespaced: true, state: { fans: [], fansLastHour: [], limits: [], }, getters: { fans: (state) => state.fans, fansLastHour: (state) => state.fansLastHour, limits: (state) => state.limits, }, mutations: { setFanInfo: (state, data) => { state.fans = data.map((fan) => { const { IndicatorLED, Location, MemberId, Name, Reading, ReadingUnits, Status = {}, PartNumber, SerialNumber, } = fan; return { id: MemberId, health: Status.Health, partNumber: PartNumber, serialNumber: SerialNumber, healthRollup: Status.HealthRollup, identifyLed: IndicatorLED, locationNumber: Location, name: Name, speed: Reading + ' ' + ReadingUnits, speedRPM: Reading, statusState: Status.State, }; }); }, setFansDynamic: (state, data) => { state.fans = data; }, setFansDynamicLastHour: (state, data) => { state.fansLastHour = data; }, setLimits: (state, data) => { state.limits = data; }, }, actions: { async patchLimits({ dispatch }, { warning, groups }) { return Promise.all( groups.map( async (group) => await api.patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', { Speed: [ { MemberId: group, UpperThresholdNonCritical: warning, }, ], }) ) ) .catch((error) => { console.log(error); throw new Error(i18n.t('pageMotherboard.toast.errorLimitUpdate')); }) .finally(() => dispatch('getLimits')); }, async getLimits({ commit }) { return await api .get('/redfish/v1/Chassis/SILA_Baseboard/Thermal') .then(({ data: { Temperatures = [] } }) => { commit('setLimits', Temperatures); }) .catch((error) => console.log(error)); }, async getFansDynamic({ commit }, { lastHour }) { let url = null; if (lastHour) { url = '/redfish/v1/TelemetryService/MetricReports/fans&period=last_hour'; } else { url = '/redfish/v1/TelemetryService/MetricReports/fans'; } return await api .get(url) .then(({ data: { MetricValues = [] } }) => { if (lastHour) { commit('setFansDynamicLastHour', MetricValues); } else { commit('setFansDynamic', MetricValues); } }) .catch((error) => console.log(error)); }, async getFanInfo({ commit }) { return await api .get('/redfish/v1/Chassis/chassis/Thermal') .then(({ data: { Fans = [] } }) => commit('setFanInfo', Fans)) .catch((error) => console.log(error)); }, }, }; export default FanStore;