Closed daneedk closed 5 years ago
@nhassink and I are running into a similar issue using this code:
for (let capability of device.capabilities) {
device.makeCapabilityListener(capability, ...);
}
For newly-created devices, it crashes on the call to device.makeCapabilityListener
:
TypeError: Cannot read property 'onoff' of null
at t.value (/node_modules/athom-api/dist/index.js:1:1060479)
at Object.module.exports [as createSwitch] (/lib/devices/switch.js:57:11)
at HomekitApp.addDevice (/app.js:165:42)
at t.api.devices.on (/app.js:45:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
In other parts of the app, it crashes because device.capabilitiesObj
(which, I assume, is being used by makeCapabilityListener
) is null
.
It's by design that this object can be null in some scenarios. You should wait for a device.update
event.
As for the crashing of athom-api, please report that issue here: https://github.com/athombv/homey-web-api-issues/issues
Can you elaborate on "some scenarios"?
Yeah, some documentation would be welcome....
Also, I don't need to know when a device is updated, I need to know when a new device is created. I don't understand there is a message emitted when a new device is created but it isn't entirely created, you have to wait some more and then it will completely created. Why isn't the event emitted after the full, succesfull creation of a device. I'm no programmer, but that would make sense to me.
A device's lifecycle is actually quite complex and some properties online exist when the device is ready
.
As for the documentation, the Web API is still experimental and unfinished.
And how do I know if a device is ready? This:
api.devices.on('device.ready', async(id) => {
console.log("device is ready")
});
doesn't trigger...
I'm also interested to hear how to determine when (not so much if) a device is ready. Right now, we're using a workaround by waiting for the first device.update
event from each device, but that feels like a hack.
(V2 rc9) The Heimdall code triggers on adding a device to Homey to see if the device qualifies to be used by Heimdall.
This code is run:
full code here
and produces the following error:
This is the device information from the
console.log(device)
capabilitiesObj is null here.I have not seen this behaviour before and not sure if it's related to https://github.com/athombv/homey-apps-sdk-issues/issues/19