Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[items] ItemPersistence: Add support for persisting TimeSeries #341

Merged
merged 9 commits into from
Jun 8, 2024

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Jun 8, 2024

This adds support for persisting a TimeSeries.

It adds a new JS TimeSeries class, which implements the same functionality as the Java TimeSeries, but in pure JS.
When this JS TimeSeries is passed to ItemPersistence#persist, a Java TimeSeries is created from it by iterating over the timestamp -> state pairs and using org.openhab.core.types.TypeParser to parse Java States from the JS types.

The helpers have been extended with a isInstant and isTimeSeries method and for all isXXX methods, a check whether the passed in type is an object has been added.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05
Copy link
Contributor Author

@jlaur Can you please test all six variantions of using the persist method?
You can have a look at the updated README how to create a TimeSeries.

If you don’t want to mess with NPM, you can download the build artifact https://github.com/openhab/openhab-js/actions/runs/9427272367/artifacts/1581551041, unzip it and copy the openHAB.js file to the node_modules folder (delete the content before).

@jlaur
Copy link
Contributor

jlaur commented Jun 8, 2024

@florian-h05 - sure, thanks! Actually I don't mind messing with NPM now that I have WSL running on my development system. However, I now tried the following:

  • Uninstalled previous version with npm uninstall openhab (after that node_modules was empty).
  • Copied your provided openhab.js into conf/automation/js/node_modules.

But got the following:

TypeError: Cannot read property "constructor" from undefined: TypeError: Cannot read property "constructor" from undefined
	at _isInstant (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)
	at _isTimeSeries (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)
	at persist (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)
	at <program> (test.js:37)
	at _run (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)
	at execute (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)
	at doExecute (C:\PROGRA~1\openHAB\conf\automation\js\node_modules\openhab.js:2)

This was before changing anything from the previous test run, i.e. line 37 (ZonedDateTime, Quantity):

items.Energi_Data_Service_Total_Price.persistence.persist(spotPrice.timestamp, totalPrice);

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
…heck, Add debug logging

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05
Copy link
Contributor Author

@florian-h05 florian-h05 added this to the to be released milestone milestone Jun 8, 2024
@florian-h05 florian-h05 added the enhancement New feature or request label Jun 8, 2024
@jlaur
Copy link
Contributor

jlaur commented Jun 8, 2024

@jlaur Can you please retry with https://github.com/openhab/openhab-js/actions/runs/9428132260/artifacts/1581671952?

Much better, previous example now works again. I'll test the others.

@jlaur
Copy link
Contributor

jlaur commented Jun 8, 2024

@florian-h05 - I can confirm that all six overloads work as expected. Good job! 👍

@florian-h05
Copy link
Contributor Author

Great 👍
I have also tested this on my dev system though I don't have a modifiable persistence service there. but what gets passed to the PersistenceExtensions looks good in the debugger.

@florian-h05 florian-h05 marked this pull request as ready for review June 8, 2024 15:19
@florian-h05 florian-h05 requested a review from a team as a code owner June 8, 2024 15:19
@florian-h05 florian-h05 merged commit 2791284 into openhab:main Jun 8, 2024
4 checks passed
@florian-h05 florian-h05 deleted the persist-timeseries branch June 8, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants