So I’m at the point, I want to create/update/delete a device through the homey-api.
I want to do it from the pairSession itself, so I use those methods:
async initHomeyApi() {
if (this.homeyApi === null) {
this.homeyApi = await HomeyAPI.createAppAPI({
homey: this.homey,
});
}
}
async updateDevice(virtualDeviceId, data) {
this.log('updateDevice:', ...arguments);
try {
// Need to retrieve the homey id of the device
let realDevice = this.getDevices().find(device => device.getData().id === virtualDeviceId);
if (realDevice === undefined) {
throw new Error('Could not find the device to delete:', virtualDeviceId);
}
await this.homeyApi.devices.updateDevice({
id: realDevice.getId(),
device: {
name: data.name,
zone: data.zoneId,
virtualClass: data.classId,
data: {
id: virtualDeviceId
}
}
});
} catch (e) {
throw e;
}
}
I get the error:
{
"statusCode": 403,
"description": "Vous n'avez pas la possibilité de faire ceci.",
"name": "Error",
"message": "Vous n'avez pas la possibilité de faire ceci."
}
As for the permission, I added to app.json:
"permissions": [
"homey:manager:api"
],
I am missing something? Or I really really need to go through fetch?
I have no idea, I’ve never done this myself. It might be that the call to updateDevice() is throwing because it might think you’re trying to set data, which isn’t allowed.