-
-
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
Add ItemStateUpdatedEvent and enable group channel-links #3141
Conversation
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/follow-profile-on-group/113445/19 |
Awesome! I really think the differentiation between report and todo makes things more clear for the user. @J-N-K |
...les/org.openhab.core/src/main/java/org/openhab/core/items/events/GroupStateUpdatedEvent.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.core/src/test/java/org/openhab/core/library/items/NumberItemTest.java
Outdated
Show resolved
Hide resolved
@spacemanspiff2007 Looks like the Regarding the timestamp: IMO it's still better to set the timestamp on the state, as that allows handling historic and future states with the same logic we have now. I wouldn't veto an addition to the events, but that should be a change for all events, not just some, so it's out of scope here. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/habapp-items-some-times-none/140425/11 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/uom-default-units-and-consequences/142360/118 |
Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: Jan N. Klug <[email protected]>
58e1ff0
to
3d79e0a
Compare
@openhab/core-maintainers Can we agree that this is useful and merge it? It makes the implementation of a solution for #3282 much easier because we have an event that carries the correct unit for state updates (which is needed e.g. for persistence). |
Thanks @J-N-K. Yes, I think it makes sense and the code looks all good to me. |
I didn't find a better label. The sending of events is not affected (there are only more events), but there is a change in behavior of the |
Additionally it's somewhat API breaking for RestAPI consumers because
It's a huge simplification and makes dealing with the RestAPI events much more pleasant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I have difficulty to understand the impact of this change on the remote OH binding. |
Is it just an additional event that can be ignored or is the behavior with the previous events impacted? |
There is a benefit in using it, but it does no harm ignoring it. All events are still fired like before. One of the limitations of |
eventPublisher.post(ItemEventFactory.createStateChangedEvent(this.name, newState, oldState)); | ||
EventPublisher eventPublisher1 = this.eventPublisher; | ||
if (eventPublisher1 != null) { | ||
eventPublisher1.post(ItemEventFactory.createStateChangedEvent(this.name, newState, oldState)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@J-N-K would you mind explaining about this change in particular? I am trying to understand why it was necessary. It seems to me that it does exactly the same thing. What have I missed?
I'm trying to understand the difference between:
if (eventPublisher != null) {
eventPublisher.post(ItemEventFactory.createStateChangedEvent(this.name, newState, oldState));
}
vs:
EventPublisher eventPublisher1 = this.eventPublisher;
if (eventPublisher1 != null) {
eventPublisher1.post(ItemEventFactory.createStateChangedEvent(this.name, newState, oldState));
}
Why the need for a temporary variable? Is it for optimisation purpose, so that it's accessing a local variable instead of resolving a class-member variable twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The eventPublisher
is @Nullable
. There is a slight chance that it is set to null
by another thread between the null-check and the usage. Therefore taking a copy ensures we don't get a NPE when using it: even if the field is set to null
, we still have the non-null reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! TIL!
Refs openhab/openhab-core#3141. Signed-off-by: Florian Hotze <[email protected]>
Refs openhab/openhab-core#3141. Signed-off-by: Florian Hotze <[email protected]>
It seems that the events that trigger rules have changed with this PR, can this be caused here? |
What exactly is broken? The |
For file-based scripts you can create rules using I just need to adjust the classnames there.
I‘ve already figured out that, thanks. Did anything change for group events? On first look, it seems that |
|
…atedEvent` (#1515) * Add logger configuration for `ItemStateUpdatedEvent` * Add logger config for `GroupStateUpdatedEvent` Refs openhab/openhab-core#3141. Signed-off-by: Florian Hotze <[email protected]>
I'm wondering why ItemStateUpdatedEvent extends The thing that puzzled me though is that previously (e.g. in openhab 3.4), I can send BusEvent.postUpdate("GroupItem", ON) and this will trigger an Item updated event for "GroupItem". You can test this using a MainUI rule in any language, then send the update event through karaf for example. This stopped working in 4.0 recently. I don't know when exactly, but I know that it wasn't this PR that changed that behaviour. I looked around in the core code but even in 3.4 I can't actually find where this would have triggered, so the fact that it triggered in 3.4 is a mystery to me, but it did. We have a test to verify this behaviour since late last year and it has always passed until recently. |
No impact on DSL rules? |
I don't think so. They just pass the event payload and that is the same (except that you really get the item state instead of something that may or may not be the item state). |
openhab/openhab-core#3141 changed the events that are passed to the rule for **StateUpdateTriggers. This adds support for the changed classnames whilst keeping backward compatibility. Signed-off-by: Florian Hotze <[email protected]>
openhab/openhab-core#3141 changed the events that are passed to the rule for **StateUpdateTriggers. This adds support for the changed classnames whilst keeping backward compatibility. Signed-off-by: Florian Hotze <[email protected]>
openhab/openhab-core#3141 changed the events that are passed to the rule for **StateUpdateTriggers. This adds support for the changed classnames whilst keeping backward compatibility. 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/openhab-4-0-milestone-discussion/145133/196 |
* Add (Group)ItemStateUpdatedEvent Signed-off-by: Jan N. Klug <[email protected]> GitOrigin-RevId: 4182980
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/openhab-4-migration-faq/148144/18 |
Is there any plan to deprecate the |
It still has an important purpose: it is issued to initiate an item state update. So the |
OK. |
No. Do you see the subtle but important difference. Let's take a DimmerItem: |
Right, I understand the difference, thank you for the explanation 👍🏻 I think we could update the documentation with this information: https://www.openhab.org/docs/developer/utils/events.html |
There has been some discussion in the past about the
ItemStateEvent
which in some cases may not carry the unit of a value even if the item has a unit (#2956).This PR adds an
ItemStateUpdatedEvent
which is fired by the item itself (similar to theItemStateChangedEvent
. Since the item knows about its dimension and unit, the new event can carry this information even if the unit is derived from a unit provider or the state description. This also clearly separates the events when the item reports something and when the item is supposed to do something:ItemStateEvent
-> the item shall update to the contained stateItemCommandEvent
-> the item receives this commandItemStateUpdatedEvent
-> the item updated the stateItemStateChangedEvent
-> the item changed the stateSince this is rather big change in functionality I would suggest to consider this for OH4 because time is running out for extensive testing (even if unit/integration test coverage is quite good).
As a side-effect group items now also report their state which makes it possible to send aggregated states (AVG/SUM/MIN/MAX/...) to the outside world by using the FOLLOW profile.