From 36ae91856c01f65ce3e178d2c16d66460de73a9e Mon Sep 17 00:00:00 2001 From: maniac103 Date: Sat, 25 May 2019 10:12:11 +0200 Subject: [PATCH] Always send correct 'item' member in SSE events (#691) * Make sure to always send the correct 'item' member in SSE events. If a change to item A causes visibility changes to item B, we previously sent an SSE event for B including the new visibility for B, but included item and state of A. This leads to client confusion, as it'll update its internal state for the widget belonging to B with the item state of A. Make sure to always send the item for B and to omit state in that case. Closes #690 Signed-off-by: Danny Baumann --- .../sitemap/internal/PageChangeListener.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java index fbe225a3b6e..d4f235f0541 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/eclipse/smarthome/io/rest/sitemap/internal/PageChangeListener.java @@ -216,7 +216,8 @@ private Set constructSitemapEvents(Item item, State state, List constructSitemapEvents(Item item, State state, List itemFilter = (i -> i.getType().equals(CoreItemFactory.LOCATION)); - event.item = EnrichedItemDTOMapper.map(item, drillDown, itemFilter, null, null); + event.item = EnrichedItemDTOMapper.map(itemToBeSent, drillDown, itemFilter, null, null); // event.state is an adjustment of the item state to the widget type. - event.state = itemUIRegistry.convertState(w, item, state).toFullString(); + final State stateToBeSent = itemBelongsToWidget ? state : itemToBeSent.getState(); + event.state = itemUIRegistry.convertState(w, itemToBeSent, stateToBeSent).toFullString(); // In case this state is identical to the item state, its value is set to null. if (event.state != null && event.state.equals(event.item.state)) { event.state = null; @@ -251,6 +255,18 @@ private Set constructSitemapEvents(Item item, State state, List