diff --git a/libs/blinkstick.js b/libs/blinkstick.js index 6124c80..a4a5edb 100644 --- a/libs/blinkstick.js +++ b/libs/blinkstick.js @@ -12,7 +12,6 @@ const MODE_POWEROFF = 'poweroff'; const LEDS_ANIMATED = []; const LEDS_STOP = []; - // find connected blinkstick(s) async function findBlinkstick(index) { let blinksticks = blinkstick.findAll(); @@ -33,12 +32,9 @@ async function simple(config) { config.timestamp = new Date().getTime(); let indices = getIndices(config); for (let index = 0; index < indices.length; index++) { - try { - await setLedAnimated(indices[index]); - await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); - } finally { - await clearLedState(indices[index]); - } + await setLedAnimated(indices[index]); + await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); + await clearLedState(indices[index]); } return { status: 'ok', @@ -56,16 +52,13 @@ async function complex(config) { } let indices = getIndices(config); for (let index = 0; index < indices.length; index++) { - try { - if (shouldLedFinish(config)) { - return {status: 'ok', time: (new Date().getTime() - config.timestamp) + 'ms'}; - } - await setLedAnimated(indices[index]); - await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); - config.repetitions.done++; - } finally { + if (shouldLedFinish(config)) { await clearLedState(indices[index]); + return {status: 'ok', time: (new Date().getTime() - config.timestamp) + 'ms'}; } + await setLedAnimated(indices[index]); + await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); + config.repetitions.done++; } return complex(config); } @@ -74,7 +67,7 @@ async function complex(config) { async function powerOff(config) { config.timestamp = new Date().getTime(); let indices = getIndices(config); - await forceStop(indices); + await forceStop(); for (let index = 0; index < indices.length; index++) { await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); logger.info('led \'' + indices[index] + '\' powered off'); @@ -121,7 +114,12 @@ async function singleAnimation(config, index) { async function stopLedsAccordingly(config) { if (config.options.index === LEDS_ALL) { - return await powerOff({id: Math.random(), mode: MODE_POWEROFF, color: '#000000', options: {index: LEDS_ALL}}); + return await powerOff({ + id: Math.random(), + mode: MODE_POWEROFF, + color: '#000000', + options: {index: LEDS_ALL} + }); } return stopLedAnimation(config.options.index); }