update persistence, add more functions
This will add all available persistence functions which are currently available in openHAB core.
The usage is now more like the original usage from the core (return types, parameters, etc).
Some of the methods are optimized for easier usage, but some of them require extra doing as before like sumSince returned a double before. The original openhab persistence function returns an abstract State.
The JRulePersistence provides now
default Optional<JRuleDecimalValue> sumSinceAsDecimal(ZonedDateTime timestamp, @Nullable String serviceId) {
return sumSince(timestamp, serviceId).map(v -> (JRuleDecimalValue) v.as(JRuleDecimalValue.class));
}
default Optional<JRuleDecimalValue> sumSinceAsDecimal(ZonedDateTime timestamp) {
return sumSinceAsDecimal(timestamp, null);
}
default Optional<JRuleValue> sumSince(ZonedDateTime timestamp) {
return sumSince(timestamp, null);
}
Optional<JRuleValue> sumSince(ZonedDateTime timestamp, @Nullable String serviceId);
Hi @querdenker2k, great that you're taking this on. Looking forward to it!
running this (not all persistence functions of course) for a few weeks and it's working
@seime your failing test ITJRulePersistence.persistenceAllTypes is working for me, i added something to be more type safe in the test. try it out please.
Still doesn't run on my side: Same exception as previously:
Due to the hard-to-read log from the docker container I'll post a screenshot which is more clear: (for the previous log, scroll sideways to see what's actually happening)
Happens both from the command line (mvn clean verify) as well as when I run the test class (ITJRulePersistence) in IntelliJ.
Note: It appears to be the printInfos method that causes the problem. Even if the test is currently testing JRuleQuantityValue, the lambda does a cast to JRuleDecimalType that fails.
If you search for target: java.lang.ClassCastException: class org.openhab.automation.jrule.rules.value.JRuleQuantityValue cannot be cast to class org.openhab.automation.jrule.rules.value.JRuleDecimalValue in the build log, you'll see that it happens there as well. The build should have failed, but it doesnt. A different issue that needs to be fixed?
Strange, this is working for me (Test function ITJRulePersistence#persistenceAllTypes). The as() function from JRuleQuantityValue (oh=QuantityType) to JRuleDecimalValue (oh=DecimalType) is a valid call which works. I use this in my productive code. What do you see in TestPersistence#209? There is no direct cast.
@querdenker2k It wasn't clear from me that I was referring to the github actions build log for this build. Did you check that log?
@seime The exception seems to be gone.