-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
Return units in persistence extension commands and support future persisted states #3736
Conversation
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/historicstate-returns-uom-but-deltasince-doesnt/148713/2 |
I understand what you want to achieve, but why did you chose |
HistoricItem was already used for minimum, maximum and previous, so wanted to stick to that. But I agree the date returned in the HistoricItem is arbitrary. I will adjust. |
1fcb4fe
to
f06b608
Compare
@J-N-K the methods now return State. As this is API breaking anyway, I also aligned method names. EvolutionRate whas the only group of methods that did not have a distinction between Since and Between in the name. I believe this is a rarely used method anyway and I think it is cleaner to have them aligned. If you feel differently, I can revert this last commit. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/blockly-quantity-type-gets-lost-when-using-persistence/150470/4 |
Any chance to get this merged for openHAB 4.1 or is that something for a new major release because it's breaking? |
@J-N-K As you had commented before, I hoped that you continue on this PR - any chance to do so?
Breaking user rules is never nice. I'm just trying to get my head around how much this might break. Do you have a typical example where user's will have to adapt their rules? Are these rather exceptional cases or do most rules break by this? |
If this gets merged for 4.1, we should try to implement a solution for #3896 for 4.1 as well to avoid having multiple sets of breaking changes. |
I have a rule that calculates the mean temperature over the last three days. It uses averageSince and then adds the unit before posting the update to the item. I still think this is a good addition, but I have no idea how to make it "less breaking". |
Similar for me, and that was the reason to create this PR. It forces you to add the unit again after retrieving the average. That means you need to 'know' the unit in the rule when retrieving to put the right unit back and it goes against the principle of UOM where you don't care. |
@J-N-K @florian-h05 @kaikreuzer If we all agree we want to do this, I could extend this PR to include a solution for #3896. |
I agree, but I'm no core maintainer ;-)
Yes, for renamed methods there would be changes required, however those are minor as the library is only wrapping For the new functionalities, I have to think about how to integrate them in the library, but I already have an idea. I can't speak for jRuby, but I guess HABApp is not affected because it is using the REST API to communicate with openHAB and not any Java calls. |
I agree that I want this change, I am just not sure when (before or after 4.1). I tend towards waiting after the release, so that we can get some feedback by snapshot and milestone users first and maybe come up with a good migration plan for 4.2. |
Yeah I've already asked myself when this should be implemented. On one hand, it would be nice to provide the right "tools" together with the new time-series support, |
Full ack. But nevertheless all existing rules using persistence extensions need to be changed. |
But why? I thought when the unit is properly set you can just post a unit with an empty value and the unit from the metadata will be assumed? Imho you should just be able to post the unitless value and everything should work as expected. I think HABApp is not affected (but I have to confirm this because currently there are no test cases) because when using the RestAPI the unit is properly assumed when not provided. |
That's true if you immediately post an update to an item that has the same unit in metadata as the unit for the item you retrieve from persistence. Sometimes, these are intermediate steps in calculations. When you retrieve something from persistence, you have to know what unit it is, and you need to consider that in each step in the calculation, convert the value if necessary yourself as it may be in the wrong unit, and then post an update to an item with the value in the unit the item expects. So the rule needs to know in each step what unit it is working in, but it is not explicit. I prefer to have the Quantities with units in the calculations all the way, to avoid all of this. That way the rule does not have to know the unit it retrieves from persistence and the unit of the item it writes to. |
I will work on extending this with logic for future states with target 4.2 for the whole PR. |
That's exactly the example @J-N-K made above and that's why I was confused because this should already work. |
My example was just a rule that needs adjustment, not an example to justify this change :-) |
What's the state here? Are the discussed extensions already included and we can review and merge? The sooner, the better: more time for testing. |
Sorry, not yet. And I won’t be able to work on it for the next few days. |
10808d8
to
0e82bfc
Compare
I've just noticed that the "between" variant of the old |
Yes, makes sense. I missed that one. |
Another change I've just noticed: Previously I could call any methods with a null serviceid to indicate that the default persistence service is to be used.
This change has caused some errors in existing scripts. Should we restore the previous behaviour? |
@mherwege I edited/updated the post above, in case you've only read the original message. |
@jimtng It has never been documented it could be used that way. Also, quickly looking through the old code again, it doesn't look like it worked for all actions, and it even gave wrong result for some (part of the query working and another part returning null and defaulting to a wrong default value, so the combination being wrong). |
@jimtng PR is created to allow null serviceId. |
Thanks! I was pondering about your previous response. I agree that it wasn't documented in the javadocs. I've started working on modifications in the jruby helper library to avoid using a null serviceId. However, I think it's a handy thing to support but either way is fine. |
… future states (#331) Refs openhab/openhab-core#3736. - Rename `Item::history` to `Item::persistence`. - Rename `HistoricItem` to `PersistedItem` and introduce `PersistedState` for state as string, Quantity & number. - Make variance, deviation, average, sum & delta return the state as `PersistedState` instead of number. - Add `**Until` methods for all existing queries. - Add `nextState` and `nextUpdate` methods. - Rename `historicState` method to `persistedState`. - Remove `latestState` method. - Remove deprecated `evolutionRate` method. - Add `removeAllStatesSince`, `removeAllStatesUntil` & `removeAllStatesBetween` methods. --------- Signed-off-by: Florian Hotze <[email protected]>
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]>
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]>
This adjusts the persistence blocks for the **breaking** changes of `org.openhab.core.persistence.extensions.PersistenceExtensions`. For NashornJS, see openhab/openhab-core#3736 for the changes. For GraalJS, see https://next.openhab.org/addons/automation/jsscripting/#itempersistence for the current API docs and openhab/openhab-js#331 for the changes. --------- Signed-off-by: Florian Hotze <[email protected]>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/jruby-scripting-official-helper-library/145072/14 |
Hello, i changed to M3 and now a rule does throw an error based on this line. Says "unknown variable or line" pointint to the "minus"... Any idea what i have to use instead? Thanks Norbert |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/unknown-variable-or-command-in-rule/156191/3 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/openhab-4-2-milestone-discussion/154316/154 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/how-to-use-time-series-from-rules-dsl-or-js/154148/23 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/how-to-use-time-series-from-rules-dsl-or-js/154148/29 |
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]> Signed-off-by: Paul Smedley <[email protected]>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/persist-state-with-own-timestamp/158160/2 |
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]> Signed-off-by: Patrik Gfeller <[email protected]>
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]>
See https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#500. Required to adjust to breaking changes from openhab/openhab-core#3736. Signed-off-by: Florian Hotze <[email protected]>
Closes #3732
Closes #3896
This PR implements unit support in all PersistenceExtension commands, returning the full value including unit for Number item types with a dimension. It therefore changes return types from DecimalType to a State type, whereby the state can include the unit.
This has been tested to work with rules DSL, and it should be possible to extend other scripting languages to support this, making calculations with historic states of items with dimensions more straightforward.
This may require adapting user rules and is therefore a breaking change.
Secondly, this PR makes sure persistence extensions work properly with persisted items in the future:
Between
commands have been adapted to be able to properly work across thenow
boundary,Untill
commands have been added, equivalent to theSince
commands.nexUpdate
andnexState
commands have been added.historicState
command has been deprecated (but still available for backward compatibility) and replaced withpersistedState
also accepting future dates.evolutionRate
command has been renamed toevolutionRateSince
,evolutionRateUntill
andevolutionRateBetween
, bringing it in line with the other commands. This change is required to allow one date signatures to differentiate betweenSince
andUntill
.evolutionRate
is deprecated and kept for backward compatibility, and interpreted asevolutionRateSince
.removeAllStates
Since
,Untill
andBetween
commands.The code now also has full null annotations and checks. In doing so, changes were required to avoid potential null issues. Many of these null issues where due to null being interpreted as now for end dates before, which is not possible when time can be in the future.
The test classes where extended and refactored to also test for all future commands.
Signed-off by: Mark Herwege [email protected]