Hi guys,
Just updated to OH 4.2.0M2 and all my js rules are broken. It seems that with the latest openhab-js the item.history is no more available and replaced with item.persistence but averageSince return an empty object…
This is a demo code, FYI, AC_Power is a numeric value
this.evaluation_start = new Date(new Date() - 1200000); // Take latest 20m, 1200s * 1000ms
this.solar_radiation = items.AC_Power.persistence.averageSince(evaluation_start);
console.log(this.solar_radiation);
It was never broken in any milestone release.
The only time it was broken was for a few snapshot builds while I was working on addressing the core changes inside the openhab-js library.
BTW in openhab-js 5, averageSince will return a PersistedState object, which will be shown as {} inside the logs. Instead of trying to log the object, log a property, e.g. averageSince(…).numericState.
@agalliazzo Can you please check your openhab-js version?
Create and run this JS script:
console.log(utils.OPENHAB_JS_VERSION);
From time to time if there are enough changes I release a new version of openhab-js, with the new version number following semver.
This will be published to npm, and possible not be fully compatible with any openHAB version older than the current snapshot.
The addon itself always comes with a version that js fully compatible to openHAB itself, so as long as you don’t manually install openhab-js, you don’t have to care about versioning and compatibility.
So for any given openhab version, you’d get a specific fixed version of jsscripting, and the only way to have it upgraded is by upgrading openhab itself? (Assuming of course you’re not manually installing / managing the npm yourself.)
In other words, the openhab-js version is married to the openhab version, just like how the addons/bindings version is married to the openhab they were distributed with?
Is the openhab-js bundled inside the addon binary?
Hi Florian, thanks for your reply, ok I will give a try in the afternoon, I miss the property numericState on the ItemPersistence object and my lack of knowledge in JS made me misunderstood the log output, that was probably my mistake…
Exactly. As long as you don’t work with npm yourself, you cannot upgrade openhab-js.
I know that with JRuby this is different because you somehow can install Gems during runtime … I haven’t found a way yet to install npm packages programmatically from the add-on.
The only thing that I currently can think of is to provide an option to provide links to bundled libraries and then have the bundles downloaded by the add-on.
Exactly. At least as long as you use the included version and don’t install it manually wit
Yes, during the add-on build a version of openhab-js specified in the add-on POM is downloaded from npm, and then bundled using webpack. The bundle is then copied into the resources/node_modules directory and shipped inside the add-on JAR (or KAR).