openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
595 stars 318 forks source link

Commands not working with openHAB 3 #2139

Closed kaikreuzer closed 4 years ago

kaikreuzer commented 4 years ago

Using openHAB 3, the app fails to send commands when clicking widgets.

Checking the device logs with adb logcat, I can see the reason:

08-13 18:24:09.482 24996 25115 E WidgetAdapter: Sending command DOWN to https://192.168.0.4:8443/rest/Shutter_ELW_East failed: status 404
08-13 18:24:09.482 24996 25115 E WidgetAdapter: org.openhab.habdroid.util.HttpClient$HttpException: Not Found
08-13 18:24:09.482 24996 25115 E WidgetAdapter:     at org.openhab.habdroid.util.HttpClient$method$$inlined$suspendCancellableCoroutine$lambda$1.onResponse(HttpClient.kt:176)
08-13 18:24:09.482 24996 25115 E WidgetAdapter:     at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
08-13 18:24:09.482 24996 25115 E WidgetAdapter:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
08-13 18:24:09.482 24996 25115 E WidgetAdapter:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
08-13 18:24:09.482 24996 25115 E WidgetAdapter:     at java.lang.Thread.run(Thread.java:929)

The url is missing the item segment for some reason... It is the same behavior using a local connection and through myopenhab.org.

@mueller-ma I hope you can help me finding a quick solution as I have upgraded my production system to openHAB 3 this week and cannot use the app anymore now... Thanks!

Environment data

Client

Server

maniac103 commented 4 years ago

Clicking widgets as in 'sitemap widgets inside the app' or 'app widgets in the launcher'?

kaikreuzer commented 4 years ago

"sitemap widgets inside the app", i.e. standard usage.

maniac103 commented 4 years ago

Did you check whether the rest API response is correct? The URL used for sending commands is the link property in the item's JSON response (see here).

kaikreuzer commented 4 years ago

Yes, I had checked it, here's the response of the REST root resource:

{"version":"4","runtimeInfo":{"version":"3.0.0","buildString":"- local build -","configFolder":"/Applications/openhab3/conf","userdataFolder":"/Applications/openhab3/userdata"},"links":[{"type":"bindings","url":"https://192.168.0.4:8443/rest/bindings"},{"type":"voice","url":"https://192.168.0.4:8443/rest/voice"},{"type":"addons","url":"https://192.168.0.4:8443/rest/addons"},{"type":"audio","url":"https://192.168.0.4:8443/rest/audio"},{"type":"module-types","url":"https://192.168.0.4:8443/rest/module-types"},{"type":"inbox","url":"https://192.168.0.4:8443/rest/inbox"},{"type":"items","url":"https://192.168.0.4:8443/rest/items"},{"type":"sitemaps","url":"https://192.168.0.4:8443/rest/sitemaps"},{"type":"ui","url":"https://192.168.0.4:8443/rest/ui"},{"type":"discovery","url":"https://192.168.0.4:8443/rest/discovery"},{"type":"habpanel","url":"https://192.168.0.4:8443/rest/habpanel"},{"type":"iconsets","url":"https://192.168.0.4:8443/rest/iconsets"},{"type":"persistence","url":"https://192.168.0.4:8443/rest/persistence"},{"type":"services","url":"https://192.168.0.4:8443/rest/services"},{"type":"spec","url":"https://192.168.0.4:8443/rest/spec"},{"type":"uuid","url":"https://192.168.0.4:8443/rest/uuid"},{"type":"events","url":"https://192.168.0.4:8443/rest/events"},{"type":"auth","url":"https://192.168.0.4:8443/rest/auth"},{"type":"things","url":"https://192.168.0.4:8443/rest/things"},{"type":"links","url":"https://192.168.0.4:8443/rest/links"},{"type":"config-descriptions","url":"https://192.168.0.4:8443/rest/config-descriptions"},{"type":"rules","url":"https://192.168.0.4:8443/rest/rules"},{"type":"channel-types","url":"https://192.168.0.4:8443/rest/channel-types"},{"type":"thing-types","url":"https://192.168.0.4:8443/rest/thing-types"},{"type":"templates","url":"https://192.168.0.4:8443/rest/templates"},{"type":"profile-types","url":"https://192.168.0.4:8443/rest/profile-types"}]}
kaikreuzer commented 4 years ago

Sorry, and here's the item's JSON response:

https://192.168.0.4:8443/rest/items/Shutter_ELW_East

{"link":"https://192.168.0.4:8443/rest/items/Shutter_ELW_East/Shutter_ELW_East","state":"0","editable":false,"type":"Rollershutter","name":"Shutter_ELW_East","label":"Fenster Ost","tags":[],"groupNames":["ELW","Shutters"]}

Which looks a bit weird as the Item name is doubled in there...

kaikreuzer commented 4 years ago

I'll investigate why this is the case, maybe there's indeed a bug in the REST API response.

maniac103 commented 4 years ago

I take you also double checked the response for the selected sitemap (rest/sitemaps/<sitemap>/<sitemap>)? That's what we use to build the data structures. I'll double check whether we do any URL mangling at parse time, but OTOH I don't think we do. Edit: we don't: https://github.com/openhab/openhab-android/blob/master/mobile/src/main/java/org/openhab/habdroid/model/Item.kt#L146

kaikreuzer commented 4 years ago

I take you also double checked the response for the selected sitemap

I didn't, thanks for reminding me of that - and that's indeed the culprit as it holds the items links without the items segment in the path.

Thanks for your help, I'll hence close this issue and create a bug fix for openhab-core!

kaikreuzer commented 4 years ago

Done with https://github.com/openhab/openhab-core/pull/1591.