Skip to content

Commit

Permalink
fix(action): Fix blinking light action
Browse files Browse the repository at this point in the history
- Updated sinonjs version to 8.1.1 to benefit from tick.async()
- Moved to inline promise with SetTimeout
  • Loading branch information
cicoub13 committed Feb 16, 2024
1 parent 50d5532 commit 1a728fb
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 158 deletions.
8 changes: 4 additions & 4 deletions server/lib/scene/scene.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const get = require('get-value');
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
const { setTimeout: promiseSetTimeout } = require('timers/promises');
const { ACTIONS, DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES, ALARM_MODES } = require('../../utils/constants');
const { getDeviceFeature } = require('../../utils/device');
const { AbortScene } = require('../../utils/coreErrors');
Expand Down Expand Up @@ -113,7 +112,7 @@ const actionsFunc = {
},
[ACTIONS.LIGHT.BLINK]: async (self, action, scope) => {
const blinkingSpeed = action.blinking_speed;
const blinkingTime = action.blinking_time;
const blinkingTime = action.blinking_time * 1000 + 1;
let blinkingInterval;
switch (blinkingSpeed) {
case 'slow':
Expand Down Expand Up @@ -141,10 +140,11 @@ const actionsFunc = {
let newValue = 0;
/* eslint-disable no-await-in-loop */
// We want this loops to be sequential
for (let i = 0; i < blinkingTime * 1000; i += blinkingInterval) {
for (let i = 0; i < blinkingTime; i += blinkingInterval) {
newValue = 1 - newValue;
await self.device.setValue(device, deviceFeature, newValue);
await promiseSetTimeout(blinkingInterval);
// eslint-disable-next-line no-promise-executor-return
await new Promise((resolve) => setTimeout(resolve, blinkingInterval));
}
/* eslint-enable no-await-in-loop */
await self.device.setValue(device, deviceFeature, oldValue);
Expand Down
Loading

0 comments on commit 1a728fb

Please sign in to comment.