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

[items] ItemHistory: Add missing methods & Enable type defs #158

Closed florian-h05 closed 1 year ago

florian-h05 commented 1 year ago

Fixes #157. Fixes #156.

Description

This PR adds the missing xxxBetween methods from the PersistenceExtensions and enables type defintions for items.getItem('MyItem').history.

The docs for ItemHistory are removed from the README, as they require manual update, but instead the JSDoc is linked.

Testing

You can install this version with npm i git+https://github.com/florian-h05/openhab-js.git#itemhistory-improvements.

All ItemHistory methods are tested and working.

I used the following script for testing:

// @ts-check
const { items, time } = require('openhab');

const item = items.getItem('Aussentemperatur').history;

const sixH = time.ZonedDateTime.now().minusHours(6);
const oneH = time.ZonedDateTime.now().minusHours(1);

console.log(item.averageBetween(sixH, oneH));
console.log(item.averageSince(sixH));

console.log(item.changedBetween(sixH, oneH));
console.log(item.changedSince(oneH));

console.log(item.deltaBetween(sixH, oneH));
console.log(item.deltaSince(oneH));

console.log(item.deviationBetween(sixH, oneH));
console.log(item.deviationSince(oneH));

console.log(item.evolutionRate(oneH)); // test depre
console.log(item.evolutionRateSince(oneH));
console.log(item.evolutionRateBetween(sixH, oneH));

console.log(item.maximumBetween(sixH, oneH));
console.log(item.maximumSince(oneH));

console.log(item.minimumBetween(sixH, oneH));
console.log(item.minimumSince(oneH));

console.log(item.sumBetween(sixH, oneH));
console.log(item.sumSince(oneH));

console.log(item.updatedBetween(sixH, oneH));
console.log(item.updatedSince(oneH));

console.log(item.varianceBetween(sixH, oneH));
console.log(item.varianceSince(oneH));
florian-h05 commented 1 year ago

@digitaldan Can you review?

For future fixes without breaking changes, do you want to review them or is it okay for you if I merge them after I tested them?

florian-h05 commented 1 year ago

Hi @digitaldan, there should be no need to test, I tested all ItemHistory methods and all worked.

Regarding the README, I removed the section because it needs manual updating every time there is a change (shouldn’t be often), but you’ve got a point that this probably should be in the docs. Sometimes it would be helpful to have the opinion of a normal user on such questions. I’ll add the ItemHistory Actions back to the README.