I am developing a custom app and currently I’m working on the settings page. The settings page needs to show a list of all devices for the current app.
The settings page makes a call to retrieve the list:
Homey.api("GET", "/devices", async (error, result) => {
if (error) return Homey.alert(error);
Homey.confirm(JSON.stringify(result));
...
}
The api.js contains a mapped method called ‘listDevices’:
const util = require('util')
module.exports = {
async listDevices({homey, query}) {
console.log("API - List Devices");
console.log(`ID: ${homey.app.id}`);
const driver = await homey.drivers.getDriver("<my driver id>");
let devices = await driver.getDevices();
console.log(`Device: ${util.inspect(devices)}`);
return devices;
}
};
Unfortunately, this doesn’t seem to work. The log in api.js does show a list of devices, but the confirm-dialog only shows an id.
I also tried moving the retrieving of the devices to my app.js, but that didn’t make a difference. I also tried retrieving the device by the ID:
let deviceIds = driver.getDevices();
let devices = [];
for (let deviceId in deviceIds) {
devices.push(driver.getDevice(deviceId));
}
But that results in an error: invalid_device_by_data.
I tried learning from other apps I found on Github. Some of those apps use ‘athom-api’, but that looks like a workaround to me.
What am I doing wrong here? I wouldn’t expect the retrieval of a list of devices for a driver to be this difficult.