openhab-core
openhab-core copied to clipboard
Unify handling of last updated channels through metadata elements
Many bindings have built virtual channels with some hairy logic to keep the "last update time". There is also dedicated profile which allows to track that items which do not have dedicated channels. While both are fair ways I believe there might be a support coming from framework core (read as openhab core) to retain this information in a volatile way without major complications to user setup.
This way could involve dedicated metadata provider which could track state changes and/or updates and make sure timestamps are retained and later provided to the UI and other elements.
Few reasons for metadata provider:
- Using metadata does not require creation of additional items.
- It exists and is associated with item already.
- Can be consumed in limited way by UI (by using oh-repeater).
What is currently missing is disclosing metadata values further through SSE, so eventual update of metadata will not be reflected in all places in a same way. I am also not sure how metadata could be consumed in rules, yet this is so far proposal to provide an unified way to track update time across all bindings.
With regard to the discussion in #3000: wouldn't a State that contains the time information be sufficient?
Now when I think of it, making it part of the item would make more sense. Update time could be streamed via SSE and utilized just like state and displayState. Not sure of how much impact it would have on openhab cloud, but adding an attribute to SSE stream is not a problem. Having it as part of state is fine on backend side too, but then encoding of state might be affected. I don't have a clear idea how we could pass a state from now and now -1 so TypeParser can deal with it.
I think the TypeParser should set the timestamp to null and whoever calls the type parser could add that information via a setTimestamp method. Another way would be to extend the parseCommand/parseState methods with an additional parameter for the timestamp.
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