Make a lightbulb/outlet blink

In the meantime, a new image :whale: is available cicoub13/gladys:blinking-lights. What has been fixed is that the action was blocking.

For example, if you add an action « Send a message », it will only happen after the light has finished blinking.

2 ways to solve this :slight_smile:

First, if you can control time in the tests!

Otherwise, you can use much smaller time values in your tests so they run faster

I had gone with the fake clock option (which seems simpler to me) but it wasn’t working. I’ll try again, thanks.

hello @cicoub13

Just 2 small remarks:
Why not multiply your constant blinking_time directly in its declaration to avoid the calculation in the loop
const blinkingTime = action.blinking_time * 1000 ;
I’ve always used doubled variable names (ii instead of i), it’s easier to trace afterwards!

For the rest, I’m not well versed in this language! :woozy_face:

Hi @cicoub,

I don’t know if this can help you or if the scenario matches:
server/test/services/netatmo/lib/netatmo.pollRefreshingValues.test.js

… I hope …

I struggled to get it to work. But with a mix of Copilot / ChatGPT / StackOverflow, it worked with this combination (especially the first test)

You’ll notice this part in the 2nd test:

    clock.tick(120 * 1000);
    clock.restore();
    // eslint-disable-next-line no-promise-executor-return
    await new Promise((resolve) =\u003e setTimeout(resolve, 50));

To advance 120 seconds, then stop the clock and fulfill the Promise. It didn’t work without clock.restore() because it conflicts with clock management (as far as I understand… ^^)

1 Like

It’s fixed, thanks

It works with SinonJS fake timers. I had to update to version 8.1.1 (previously 7.2.4) to benefit from clock.tickAsync().

By the way, they’re up to version 17 :sweat:

Thanks @Terdious and @pierre-gilles, those time-related tests weren’t easy :sweat_smile:

I’ll let you know when everything is ready

2 Likes

PR ready (functionally, development, tests) :tada:

3 Likes

Thanks for the PR @cicoub13 :slight_smile:

I found a small bug when doing a real-world test:

But nothing major, the behavior otherwise works well!

1 Like

It’s fixed

4 Likes

Thanks for the fix @cicoub13! It’s good for me, it’s merged into master and it will be released in the next version of Gladys :slight_smile:

4 Likes

This feature is available in Gladys Assistant 4.38 :slight_smile:

I’m closing this thread to free up the votes, feel free to create other threads in case of bugs/feedback :slight_smile:

Thanks to @cicoub13 for the development :folded_hands:

4 Likes