From 71ffcb981c4f19f07136262a496e6b9efc6c43c7 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Sun, 22 Oct 2023 14:22:33 +0200 Subject: [PATCH] Fix parsing of SSE topic for groups (#3503) There can be an optional group in the topic path. Signed-off-by: mueller-ma --- .../habdroid/background/ItemsControlsProviderService.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/background/ItemsControlsProviderService.kt b/mobile/src/main/java/org/openhab/habdroid/background/ItemsControlsProviderService.kt index e97d33693d..ecdadff663 100644 --- a/mobile/src/main/java/org/openhab/habdroid/background/ItemsControlsProviderService.kt +++ b/mobile/src/main/java/org/openhab/habdroid/background/ItemsControlsProviderService.kt @@ -97,7 +97,13 @@ class ItemsControlsProviderService : ControlsProviderService() { } val topic = event.getString("topic") val topicPath = topic.split('/') - if (topicPath.size != 4) { + /* Possible formats: + * - openhab/items//statechanged + * - openhab/items///statechanged + * When an update for a group is sent, there's also one for the individual item. + * Therefore always take the element on index two. + */ + if (topicPath.size !in intArrayOf(4, 5)) { throw JSONException("Unexpected topic path $topic") } val item = allItems[topicPath[2]]