
Multi-device driver ?
I'm trying to write a single driver able to handle all the hardware line made by my company. Thanks to enableDiscovery (https://neeoinc.github.io/neeo-sdk/#lib-device-devicebuilder.js-enablediscovery) I can create distincts devices with distincts device id matching the hardware devices discovered on the network. I tested it, it works. But how am I supposed to tell which UI element belong to which device ? I'm asking because all devices don't have the same features set.
For instance: I can define discovery as follow
.enableDiscovery( { headerText: 'HELLO HEADER', description: 'ADD SOME ADDITIONAL INFORMATION HOW TO PREPARE YOUR DEVICE' }, function() { return [ { id: 'unique-device-id-001', name: 'first device', }, { id: 'unique-device-id-002', name: 'second device' } ]; } )
then I want to had a switch to unique-device-id-001 only, but according to https://neeoinc.github.io/neeo-sdk/#lib-device-devicebuilder.js-addswitch , addSwitch doesn't take any device id parameter.
Is this even possible ? or am I supposed to solve this at higher level by defining multiple drivers like this :
driverObject1= neeoapi.buildDevice("Device 1"); driverObject2= neeoapi.buildDevice("Device 2"); .... const neeoSettings = { brain: "192.168.0.9", port: 1104, name: "Yoctopuce", devices: [driverObject1, driverObject2] }; .... neeoapi.startServer(neeoSettings)
-
It depends... :-)
if the capabilities of a specific model is static, let’s say there are two models, where model A has a power toggle button and model B has a power toggle and a switch, then exposing them as two separate drivers is the best solution. Both can use the same controller code but the capabilities are pre defined and offered separately by your driver.
When the capabilities are dynamic and can differ per installment/per user then SDK version >=0.52.x has a nice feature where you can define the capabilities at the discovery stage.
it requires the >=0.52 firmware that is not yet released at the time I write this.
Here is an example driver where I dynamically build drivers for MHUB uControl. https://github.com/nklerk/neeo_driver-mhub/blob/master/devices/mhub/uControlController.js
a NEEO example can be found here:https://github.com/NEEOInc/neeo-sdk-examples/tree/next/lib/dynamicDeviceBuilder