Having just taken a quick look at the plugin you posted, it looks like the problem is in onSynchronizeDevices()
, you store the new device in the plugin’s Devices
array with:
plugin.Devices[Keypad1.Id] = Keypad1;
That is, you index it off its Id
, which is set to be 1
.
But in onConnect()
you retrieve it based on the plugin’s name:
var mainDevice = plugin.Devices[plugin.Name];
Since the plugin’s name is Keypad
and not 1
, plugin.Devices[plugin.Name]
is undefined.
I didn’t try to run the code, but just took a look at it. But my guess is if you replace the onSynchronizeDevices()
line to be:
plugin.Devices[plugin.Name] = Keypad1;
that will fix your problem.
EDIT: I should have read the thread more carefully, that’s exactly what @LJR suggested as well.
There is a related issue you may be describing, which is that the device is not always initialized within THR at the onSynchronizeDevices()
stage. I don’t know if the startup process has been fully documented, but I have observed that when you call onSynchronizeDevices()
, it will also call onConnect()
but the device object itself is available at that point. I would suggest guarding your onConnect()
(and maybe onPoll()
as well) with:
if(mainDevice) {
...
}
logic, so that those calls don’t do anything unless there is actually a valid device object.
Hope that helps!