fix bug sonrqube
This commit is contained in:
parent
c2e5d55ed2
commit
1a755be7fb
1 changed files with 15 additions and 13 deletions
|
@ -557,7 +557,6 @@ export const RemoteService = {
|
||||||
*/
|
*/
|
||||||
saveAutomation: (data) => {
|
saveAutomation: (data) => {
|
||||||
const { automation, triggerList, order } = data;
|
const { automation, triggerList, order } = data;
|
||||||
console.log('automation: ', automation, triggerList, order);
|
|
||||||
automation.triggers = [];
|
automation.triggers = [];
|
||||||
automation.scenes = [];
|
automation.scenes = [];
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
|
@ -566,15 +565,16 @@ export const RemoteService = {
|
||||||
const urlRangeTrigger = '/rangeTrigger';
|
const urlRangeTrigger = '/rangeTrigger';
|
||||||
const urlScenePriority = '/scenePriority';
|
const urlScenePriority = '/scenePriority';
|
||||||
|
|
||||||
const rangeTriggerList = triggerList.filter((trigger) => trigger.hasOwnProperty('operand'));
|
const rangeTriggerList = triggerList.filter((trigger) => 'operand' in trigger);
|
||||||
const booleanTriggerList = triggerList.filter(
|
const booleanTriggerList = triggerList.filter(
|
||||||
(trigger) => !trigger.hasOwnProperty('operand'),
|
(trigger) => !('operand' in trigger),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Endpoint.post(urlAutomation, {}, automation).then(
|
return Endpoint.post(urlAutomation, {}, automation).then(
|
||||||
async (automationRes) => {
|
async (automationRes) => {
|
||||||
const { id } = automationRes.data;
|
const { id } = automationRes.data;
|
||||||
// Introduce the range triggers in the automation
|
// Introduce the range triggers in the automation
|
||||||
|
const resRangeTriggers = [];
|
||||||
for (const t of rangeTriggerList) {
|
for (const t of rangeTriggerList) {
|
||||||
const trigger = {
|
const trigger = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
|
@ -582,38 +582,40 @@ export const RemoteService = {
|
||||||
operator: t.operand,
|
operator: t.operand,
|
||||||
range: t.value,
|
range: t.value,
|
||||||
};
|
};
|
||||||
const resRange = await Endpoint.post(urlRangeTrigger, {}, trigger);
|
|
||||||
automation.triggers.push(resRange.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
resRangeTriggers.push(Endpoint.post(urlRangeTrigger, {}, trigger));
|
||||||
|
}
|
||||||
|
automation.triggers = (await Promise.all(resRangeTriggers)).map((v) => v.data);
|
||||||
|
|
||||||
|
const resBoolTriggers = [];
|
||||||
for (const t of booleanTriggerList) {
|
for (const t of booleanTriggerList) {
|
||||||
const trigger = {
|
const trigger = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
deviceId: t.device,
|
deviceId: t.device,
|
||||||
on: t.value,
|
on: t.value,
|
||||||
};
|
};
|
||||||
const resBoolean = await Endpoint.post(
|
resBoolTriggers.push(Endpoint.post(
|
||||||
urlBooleanTrigger,
|
urlBooleanTrigger,
|
||||||
{},
|
{},
|
||||||
trigger,
|
trigger,
|
||||||
);
|
));
|
||||||
automation.triggers.push(resBoolean.data);
|
|
||||||
console.log('TRIGGERS: ', automation);
|
|
||||||
}
|
}
|
||||||
|
automation.triggers.push(...((await Promise.all(resBoolTriggers)).map((v) => v.data)));
|
||||||
|
|
||||||
|
const resScenePriorities = [];
|
||||||
for (const [priority, sceneId] of order.entries()) {
|
for (const [priority, sceneId] of order.entries()) {
|
||||||
const scenePriority = {
|
const scenePriority = {
|
||||||
automationId: id,
|
automationId: id,
|
||||||
priority,
|
priority,
|
||||||
sceneId,
|
sceneId,
|
||||||
};
|
};
|
||||||
const resScenes = await Endpoint.post(
|
resScenePriorities.push(Endpoint.post(
|
||||||
urlScenePriority,
|
urlScenePriority,
|
||||||
{},
|
{},
|
||||||
scenePriority,
|
scenePriority,
|
||||||
);
|
));
|
||||||
automation.scenes.push(resScenes.data);
|
|
||||||
}
|
}
|
||||||
|
automation.scenes = (await Promise.all(resScenePriorities)).map((v) => v.data);
|
||||||
automation.id = id;
|
automation.id = id;
|
||||||
dispatch(actions.automationSave(automation));
|
dispatch(actions.automationSave(automation));
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue