Commit d76df389 by HaOuiha

.

parent 8b082b3a
......@@ -88,17 +88,22 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
const getBreakerStatus = async deviceId => {
try {
const {
data: {
shadow: { data },
},
} = await apolloQuery(READ_SHADOW, { deviceid: deviceId });
const res = await apolloQuery(QUERY_ONLINE_STATUS, { deviceid: deviceId });
const onlineStatus = res.data.device[0].status;
// const {
// data: {
// shadow: { data },
// },
// } = await apolloQuery(READ_SHADOW, { deviceid: deviceId });
const res1 = await apolloQuery(READ_SHADOW, { deviceid: deviceId });
const breakerStatusData = res1.data.shadow.data;
// const response = await apolloQuery(READ_SHADOW, { deviceid: deviceId });
// console.log(response);
const res2 = await apolloQuery(QUERY_ONLINE_STATUS, { deviceid: deviceId });
const onlineStatus = res2.data.device[0].status;
// console.log(onlineStatus);
const tempBreakerStatus = _.pick(data, ['SM1']);
const tempBreakerStatus = _.pick(breakerStatusData, ['SM1']);
const breakerStatus = tempBreakerStatus.SM1.BK_S;
return { breakerStatus, onlineStatus };
} catch (e) {
......
......@@ -217,7 +217,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
}
};
export const setMainStatus = settingValue => (dispatch, getState) => {
export const setMainStatus = settingValue => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData, breakerStatus } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
......@@ -237,13 +237,13 @@ export const setMainStatus = settingValue => (dispatch, getState) => {
try {
const desiredBreakerStatus = { ...breakerStatus, SM1: { BK_S: settingValue ? 1 : 0 } };
dispatch(getBreakersStatusAction(desiredBreakerStatus));
apolloMutation(WRITE_SHADOW, { deviceid: selectedDeviceId, data: writingCommand });
await apolloMutation(WRITE_SHADOW, { deviceid: selectedDeviceId, data: writingCommand });
} catch (error) {
console.log(error);
}
};
export const setSubBreakerStatus = (settingValue, MainIndex, SubIndex) => (dispatch, getState) => {
export const setSubBreakerStatus = (settingValue, MainIndex, SubIndex) => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData, breakerStatus } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
......@@ -267,7 +267,7 @@ export const setSubBreakerStatus = (settingValue, MainIndex, SubIndex) => (dispa
},
};
dispatch(getBreakersStatusAction(desiredBreakerStatus));
apolloMutation(WRITE_SHADOW, { deviceid: selectedDeviceId, data: writingCommand });
await apolloMutation(WRITE_SHADOW, { deviceid: selectedDeviceId, data: writingCommand });
} catch (error) {
console.log(error);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment