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) => {
|
||||
const { automation, triggerList, order } = data;
|
||||
console.log('automation: ', automation, triggerList, order);
|
||||
automation.triggers = [];
|
||||
automation.scenes = [];
|
||||
return (dispatch) => {
|
||||
|
@ -566,15 +565,16 @@ export const RemoteService = {
|
|||
const urlRangeTrigger = '/rangeTrigger';
|
||||
const urlScenePriority = '/scenePriority';
|
||||
|
||||
const rangeTriggerList = triggerList.filter((trigger) => trigger.hasOwnProperty('operand'));
|
||||
const rangeTriggerList = triggerList.filter((trigger) => 'operand' in trigger);
|
||||
const booleanTriggerList = triggerList.filter(
|
||||
(trigger) => !trigger.hasOwnProperty('operand'),
|
||||
(trigger) => !('operand' in trigger),
|
||||
);
|
||||
|
||||
return Endpoint.post(urlAutomation, {}, automation).then(
|
||||
async (automationRes) => {
|
||||
const { id } = automationRes.data;
|
||||
// Introduce the range triggers in the automation
|
||||
const resRangeTriggers = [];
|
||||
for (const t of rangeTriggerList) {
|
||||
const trigger = {
|
||||
automationId: id,
|
||||
|
@ -582,38 +582,40 @@ export const RemoteService = {
|
|||
operator: t.operand,
|
||||
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) {
|
||||
const trigger = {
|
||||
automationId: id,
|
||||
deviceId: t.device,
|
||||
on: t.value,
|
||||
};
|
||||
const resBoolean = await Endpoint.post(
|
||||
resBoolTriggers.push(Endpoint.post(
|
||||
urlBooleanTrigger,
|
||||
{},
|
||||
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()) {
|
||||
const scenePriority = {
|
||||
automationId: id,
|
||||
priority,
|
||||
sceneId,
|
||||
};
|
||||
const resScenes = await Endpoint.post(
|
||||
resScenePriorities.push(Endpoint.post(
|
||||
urlScenePriority,
|
||||
{},
|
||||
scenePriority,
|
||||
);
|
||||
automation.scenes.push(resScenes.data);
|
||||
));
|
||||
}
|
||||
automation.scenes = (await Promise.all(resScenePriorities)).map((v) => v.data);
|
||||
automation.id = id;
|
||||
dispatch(actions.automationSave(automation));
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue