I’m trying to use the default pairing templates to capture a pincode which I want to store in the device store as it is required to setup a connection to the device.
The problem I am having is that I can’t seem to find a list of events emitted by the default pairing templates. In order to store the pincode I need to know which device the user selected from the device list, so preferably an event emitted by the list_devices template after selecting the device and moving to the next screen.
So far I have uncovered there is an add_device
event emitted by, I think, the add_devices
template. But this event gets emitted only after the device is added and initialized which is inconvenient as I want to pass the pincode capture before the device is created.
In summary it would be great if the events emitted by the default templates would be documented. And it would be even better if the source of the default templates could be shared so developers can easily use these as basis for their custom pairing views. We could then also see the events emitted.
For reference some code:
public async onPair(session: PairSession) {
session.setHandler('list_devices', this.onPairListDevices.bind(this));
session.setHandler('add_device', this.add_device.bind(this));
session.setHandler('pincode', this.onPinCode.bind(this));
}
public async add_device(...args: any[]) {
this.log('add_devices', args);
}
public async onPinCode(...args: any[]) {
this.log('onPinCode', args);
return true;
}
Thanks for the reply! That part I had already figured out and wasn’t what I asked. What I’m interested in is how to cary over the pin code to the device store.
Eventually the front end code calls the device add to create a new device, and I want that device to be created with the pincode captured during the pairing session. So somehow that pincode needs to be included in the device create/add call made by the UI.
I spend sometime inspecting the templates and js code using developer tools and conclude there isn’t a good way to do this right now making the pincode template rather useless.
For now I will work around this by creating a object keyed by device-id in the driver that stores the pincode (if valid) and upon creation of the device in the onAdd lifecycle hook reads that from the driver.
This workaround was only possible by using the device selected event emitted by the default device list template. That event isn’t documented so I had to dive into the developer console to find it. I use that to store the device id of the selectee device on the pairing session context object.
It would have been helpful if all events emitted by the default templates cloud be documented including the params.
Overall I am noticing documentation is not always complete and lacking in detail. That’s okay for opensource projects as you can read the code and understand how something works, but for closed source applications it is a pain.
So Athom pretty please put some more work in extending the public docs 
A request that has been made repeatedly over the years, but Athom doesn’t seem to be interested in improving existing documentation (only adding documentation for Shiny New Features).
True, but it never hurts to keep asking. I’m sure that the team is aware of the lack of documentation. I would even be fine if they would release parts of the templates and things like that in a public repo so the community can view them more easily and also make suggestions for changes and new templates.
Feel free to post a request here: GitHub · Where software is built
1 Like