Closed maniac103 closed 1 year ago
Whilst this is a breaking change, I have nothing against it because I see the benefits of changing the ItemHistory class to also return a timestamp as well as we should return the string state where provided to return the value with its unit. The next release of the library already includes a breaking change, so let’s add on more!
Do you want to implement that yourself?
I can do it, but I'd appreciate guidance on how exactly the returned result should look like. Just an object with a string named state
and a ZonedDateTime
named timestamp
?
That’s exactly what I’d expect.
This object with those two properties would get returned for all PersistenceExtensions
methods that return a HistoricItem, see https://www.openhab.org/javadoc/latest/org/openhab/core/persistence/extensions/persistenceextensions.
Just keep in mind that all methods can return null, and convert the Java ZonedDateTime to its JS counterpart. Have a look at the utility functions at the bottom of the JS file.
In one of my rules, I use
PersistenceExtensions
to grab a value with timestamp to fill 2 items with it:Since I need the timestamp, I can't use
item.history
. It would be great if theItemHistory
object could handle that situation, e.g. by returning an object containing both state and timestamp (the latter asZonedDateTime
), for all applicable calls:maximumSince
maximumBetween
minimumSince
minimumBetween
previousState
(currently implemented as 2 methods, only case where timestamp can be returned)That way, the above rule would become much shorter: