WebThingsIO / thing-url-adapter

Proxy adapter for Web Thing API endpoints
Mozilla Public License 2.0
22 stars 18 forks source link

Things adapter parses WebThing API description wrongly #62

Closed dvas0004 closed 5 years ago

dvas0004 commented 5 years ago

Symptoms:

screenshot from 2018-12-05 12-46-03

Reproduction:

screenshot from 2018-12-05 16-24-17

Expected:

screenshot from 2018-12-05 13-40-21

Note in the above screenshot the "brightness" is populated with 50% and basically everything works as expected

Troubleshooting / Potential Solution:

Looking at the run-app logs, we see some interesting entries:

screenshot from 2018-12-05 12-43-33

Note the "undefined" being appended to the URL. Searching for the error message "Failed to connect..." in thing-url-adapter.js, I managed to trace the error to line 105.

Currently you expect a single 'href' to be present in JSON returned from the WebThings API, however what's being returned is actually a "links" array, which then contains the 'href' string you are looking for, for example:

{"name":"MacDetector","href":"/","@context":"https://iot.mozilla.org/schemas","@type":[],"properties":{"DavidPresent":{"@type":"OnOffProperty","label":"David Present","type":"boolean","description":"If David MAC address is present","readOnly":false,"links":[{"rel":"property","href":"/properties/DavidPresent"}]},
...

Changing line 105 in thing-url-adapter.js to:

const propertyUrl = this.baseUrl + propertyDescription.links[0].href;

solves the issue

Notes to anyone trying the above workaround:

mrstegeman commented 5 years ago

Do you have any other details? What's being parsed improperly?

dvas0004 commented 5 years ago

Sorry @mrstegeman! I was click-happy and created the issue without adding the description. Issue updated :)

mrstegeman commented 5 years ago

@dvas0004 Yeah, the webthing libraries were all just updated for the latest spec, but the adapter has not yet been updated. If you have an immediate need, you can step back to the 0.9.X library series. Otherwise, I plan to update the add-on this week.

dvas0004 commented 5 years ago

No worries! The workaround I described is working sufficiently for me at the moment :)

On Wed, 5 Dec 2018 at 17:12, Michael Stegeman notifications@github.com wrote:

@dvas0004 https://github.com/dvas0004 Yeah, the webthing libraries were all just updated for the latest spec, but the adapter has not yet been updated. If you have an immediate need, you can step back to the 0.9.X library series. Otherwise, I plan to update the add-on this week.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mozilla-iot/thing-url-adapter/issues/62#issuecomment-444519695, or mute the thread https://github.com/notifications/unsubscribe-auth/AFlDbTG1ZFj3f7IbTbbUTPPAUI_qpY59ks5u1-J3gaJpZM4ZC0x9 .