fix bug sonrqube

This commit is contained in:
britea 2020-05-12 16:09:59 +02:00
parent c2e5d55ed2
commit 1a755be7fb

View File

@ -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));
},