I’m trying to get a simple custom pairing flow to work. But i get strange results and is clearly missing something obvious.
Pairing via Homey Developer Tools always get me back to the same view (manual_pairing) when i press the ‘add device’ button. I can see in the logs that the view for some reason is shown twice.
Pairing in app gives a blank screen after pressing the button. Cancelling the pairing from there actually adds adds the device. I have tried with and without a second view called ‘done’ that has a Homey.done()
Any ideas? Thanks in advance!
Flow:
- Three fields in a form
- A connectivity/validation check in the driver/backend
- createDevice from view
- Done
driver.compose.json
"pair": [
{
"id": "manual_pairing",
"navigation": { "next": "done" }
},
{
"id": "done"
}]
driver.js
async onPair(session) {
session.setHandler('manual_pairing', async (data) => {
//TODO: A backend connection test will be made from here, for now lets assume everything is ok.
console.log(`FE emitted from manual_pairing - ${data.ipaddress}`);
return true;
});
session.setHandler("showView", async (viewId) => {
console.log("debug - view: " + viewId);
});
}
manual_pairing.html
...3 field form and a button...
<script type="application/javascript">
let connectElement = document.getElementById('connect');
connectElement.addEventListener('click', (e) => manualPairing());
function manualPairing() {
let ipaddress = document.getElementById('ipaddress').value.trim();
let deviceid = document.getElementById('deviceid').value.trim();
let accesscode = document.getElementById('accesscode').value.trim();
Homey.emit('manual_pairing', {
ipaddress: ipaddress,
deviceid: deviceid,
accesscode: accesscode
})
.then(result => {
console.log('back from backend with result ' + result);
if (result) {
console.log('debug - adding ' + deviceid);
Homey.createDevice({
name: deviceid,
data: {
id: deviceid,
},
store: {},
settings: {
ipaddress: ipaddress,
accesscode: accesscode
}
})
.then(() => {
console.log('Device created successfully');
//Homey.done();
})
.catch(error => {
console.error('Error creating device:', error);
});
console.log('debug - added ' + deviceid);
}
});
}
</script>
done.html
<script type="application/javascript">
Homey.done();
</script>
Logs
Backend
debug - view: manual_pairing
FE emitted from manual_pairing - testip
debug - view: manual_pairing