openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Update to addon changes #169

Closed florian-h05 closed 1 year ago

florian-h05 commented 1 year ago

Fixes #168.

Changes

Testing

I have also verified that the library is still working under older versions of the addon that are running an older GraalJS and therefore NodeJS version.

Use the following script to verify all relevant changes:

const { actions, time } = require('openhab');

// Test whether access to raw timer creation methods is still possible but logs a warning
const now = time.ZonedDateTime.now();

actions.ScriptExecution.createTimer('timer1', now.plusSeconds(2), () => {
  console.info('Timer with identifier ran');
});
actions.ScriptExecution.createTimer(now.plusSeconds(4), () => {
  console.info('Timer without identifier ran');
});

const foo = 'myVar';

actions.ScriptExecution.createTimerWithArgument('timer2', now.plusSeconds(6), foo, () => {
  console.info('Timer with identifier and var ran: ' + foo);
});

actions.ScriptExecution.createTimerWithArgument(now.plusSeconds(8), foo, () => {
  console.info('Timer without identifier and with var ran: ' + foo);
});

// Test examples from the README updates

// Example 1

var myVar = 'Hello world!';

// Schedule a timer that expires in ten seconds
setTimeout(() => {
  console.info(`Timer expired with myVar = "${myVar}"`);
}, 10000);

myVar = 'Hello mutation!'; // When the timer runs, it will log "Hello mutation!" instead of "Hello world!"

// Example 2

// Function generator for the timer's callback function
function cbFuncGen (myVariable) {
  return function () {
    console.info(`Timer expired with myVar = "${myVariable}"`);
  };
}

var bar = 'Hello world!';

// Schedule a timer that expires in ten seconds
setTimeout(cbFuncGen(bar), 12000);

bar = 'Hello mutation!'; // When the timer runs, it will log "Hello world!"
florian-h05 commented 1 year ago

@digitaldan @jpg0 @rkoshak (sorry for pinging you all) This is the follow-up PR for https://github.com/openhab/openhab-addons/pull/13623.

Could any of you please review? We haven't much time time left to get this into the milestone, so at some point I will merge without review.

jlaur commented 1 year ago

Could any of you please review?

I'm no JavaScript expert and not a maintainer of this repository, so I'm afraid I can't help much. When you have this PR reviewed and merged and a new lib is released, I'll of course help merging the new version into the addons repository.

florian-h05 commented 1 year ago

@jlaur

I'm no JavaScript expert and not a maintainer of this repository, so I'm afraid I can't help much.

You wouldn't be the first reviewer that is no maintainer, since we are only two maintainers and digitaldan is not always available when a time critic PR needs to be merged.

I am aware that you are no JS expert, but it would be great if you could have a look at the README changes.

When you have this PR reviewed and merged and a new lib is released, I'll of course help merging the new version into the addons repository.

I will definitely come back to that offer!