WebThingsIO / example-adapter

Example adapter add-on for WebThings Gateway
Mozilla Public License 2.0
34 stars 20 forks source link

Import classes in a standard way #14

Closed cr0ybot closed 5 years ago

cr0ybot commented 5 years ago

The add-on classes (Adapter, Device, etc) are being imported in a strange way that doesn't seem to be relevant to externally-developed (3rd party) add-ons.

The documentation specifies that imports should be done like so:

const { Adapter, Device, Property } = require('gateway-addon');

Currently it looks like the code is looking for the modules in a parent folder, but these files do not exist in the context of the addons folder that our 3rd party addons are meant to live in.

mrstegeman commented 5 years ago

When we first created the add-on system (API level 1), all of the imports lived in the gateway itself. The code you see in this adapter is for backwards compatibility.

However, that can probably be removed now, as the old style went away a long time ago.

cr0ybot commented 5 years ago

Thanks for the explanation! Maybe this backwards-compatible way of importing could be commented out with an explanation that its for API level 1?

Would you be able to point me towards where the API level is documented (or maybe the source code)? I've been mostly going off referencing other addon's source code, and it seems like they all have the min/max api level set to 2, but I couldn't find anywhere if the latest API level is currently 2 and what the differences are.

mrstegeman commented 5 years ago

There isn't really any documentation on that, because the only major difference between 1 and 2 was that the imports were moved into a proper package for level 2.

cr0ybot commented 5 years ago

Thanks for answering all of my persistent questions! You folks are doing great work.