WebThingsIO / example-adapter

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

Use manifest name property instead of inexistent id #26

Closed MichaelKohler closed 3 years ago

MichaelKohler commented 3 years ago

The id property doesn't exist anymore, name is now pointing to the ID: https://github.com/WebThingsIO/gateway/blob/819b8cd4151ace303a6d2564fd70ef5d8cf5a0a3/src/addon-loader.js#L53

mrstegeman commented 3 years ago

Approved too quickly. manifest.id is actually coming directly from manifest.json.

mrstegeman commented 3 years ago

The code you were looking at is the legacy interface that we shouldn't be using anymore. I've been unable to take it out, though, for technical reasons.

MichaelKohler commented 3 years ago

Should have added this info initially, I'm getting an error in my adapters when using manifest.id.

2020-12-03 14:33:19.874 ERROR  : Invalid message received: {
  "messageType": 4096,
  "data": {
    "adapterId": "NeeoAdapter",
    "name": "NeeoAdapter",
    "pluginId": "neeo-adapter"
  }
}

In 1.0.0 there is a second error going with that:

2020-12-04 10:13:19.757 ERROR  : Invalid message received: {
  "messageType": 4096,
  "data": {
    "adapterId": "NeeoAdapter",
    "name": "NeeoAdapter",
    "pluginId": "neeo-adapter"
  }
}
2020-12-04 10:13:19.758 ERROR  : Validation error: [
  {
    "keyword": "required",
    "dataPath": ".data",
    "schemaPath": "#/properties/data/required",
    "params": {
      "missingProperty": "packageName"
    },
    "message": "should have required property 'packageName'"
  }
]

Here's the second parameter logged inside the constructor:

{
  name: 'neeo-adapter',
  display_name: 'NEEO Adapter',
  moziot: {
    exec: '{nodeLoader} {path}',
    schema: { type: 'object', required: [], properties: [Object] },
    config: { neeoIP: '192.168.0.229', devices: [Array] }
  }
}

When using manifest.name this error goes away.

mrstegeman commented 3 years ago

The key is to make sure you're using const manifest = require('./manifest.json') (or similar path), rather than using the manifest variable that's passed in from the add-on loader.

MichaelKohler commented 3 years ago

Oh no, now I get it. Should have looked closer, then I would have seen that it's not actually using that param but rather the require above. Sorry!