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

RFC: Add an ItemStateUpdatedEvent #2956

Closed
J-N-K opened this issue May 8, 2022 · 4 comments · Fixed by #3141
Closed

RFC: Add an ItemStateUpdatedEvent #2956

J-N-K opened this issue May 8, 2022 · 4 comments · Fixed by #3141
Labels
enhancement An enhancement or new feature of the Core

Comments

@J-N-K
Copy link
Member

J-N-K commented May 8, 2022

Follow-Up To #1092, #1093, #2286

There has been quite some confusion about the ItemStateEvent which is not emitted by the item if the state was updated but by an "external" source to update the item's state. Since these external sources do not necessarily know about the item type (e.g. a switch in the UI is agnostic of the item being Color, Dimmer or Switch and will send ON or OFF) or the unit of the item, the state in the ItemStateEvent does not reflect the new item's state.

It seems that there are use cases for an event that is emitted if the state was updated and what the new state is (similar to the ItemStateChangedEvent).

@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label May 8, 2022
@J-N-K
Copy link
Member Author

J-N-K commented May 8, 2022

@spacemanspiff2007 I would appreciate if you could shortly describe what the use-case for the ItemStateUpdated/GroupStateUpdated event is.

@spacemanspiff2007
Copy link
Contributor

Thank you @J-N-K for consolidating the issues.

When consuming the events I need an event on which I can set the locally cached item state accordingly.
Originally I thought that the ItemStateEvent is exactly that event since the name indicates that a new item state has been set.
This led to the following understanding:

sequenceDiagram
    participant openHAB
    participant device
    participant sse listener

openHAB->>+device: command
openHAB->>sse listener: ItemCommandEvent
device->>-openHAB: report state

loop
    openHAB->>openHAB: Set item state
end

openHAB->>sse listener: ItemStateEvent
openHAB->>sse listener: ItemStateChangedEvent (optional)
Loading

However it's very confusing that the ItemStateEvent data does not match the data from ItemStateChangedEvent.
I had to implement the logic myself that transforms the values to the corresponding item values:
e.g. ON to 100% brightness or 30,100,100 in case of a HSB value.

I can not use the ItemStateChangedEvent to set the value because the ItemStateEvent comes before it and many users trigger their rules on the ItemStateEvent. This would lead to the case where e.g. the ItemStateEvent signals "ON" but the HABApp internal item state is still OFF because the ItemStateChangedEvent comes after the ItemStateEvent.


I hope the example makes it clear that there is the need for an event which contains the current, updated item state.
This event has to be emitted before the ItemStateChangedEvent! It could then have the UOM set as an additional field, too so I don't have to split the value on the last white space.
Imho it's good if the API is consistent so this new event should be sent for item groups, too.


Since the ItemStateEvent contains the update information used internally by openHAB I would propose to not expose these events over the API. Since removing things is always hard how about just logging a message when an event listener connects that listens to the ItemStateEvents that there is a new event available that should be used instead. Then after an arbitrary time frame the ItemStateEvent can be removed.

@spacemanspiff2007
Copy link
Contributor

Other useful things that this event could implement:

  • Separation of State and UoM. UoM then should be accessible through extra field
  • Timestamp when the Item updated the state

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-0-wishlist/142388/449

@github-project-automation github-project-automation bot moved this from In Progress to Done in openHAB 4 Issue Tracking Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants