athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

`device.makeCapabilityListener` sometimes fails #3

Closed robertklep closed 1 year ago

robertklep commented 5 years ago

In certain cases, the following code crashes in device.makeCapabilityListener:

for (let capability of device.capabilities) {
  device.makeCapabilityListener(capability, ...);
}

The error:

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)
WeeJeWel commented 5 years ago

@jeroenvollenbrock This most likely happens when the device isn't ready. A better error should be thrown imo.

mskg commented 5 years ago

I can confirm this behavior for other event types and see a significant amount of errors in Sentry logs.

TypeError: Cannot read property 'target_temperature' of null
  File "/node_modules/athom-api/index.js", line 1, col 1122810, in t.value
    '{snip} ;if(!r)throw new TypeError("unsupported capability");return new this.constructor.CapabilityInstance({device:this,capabilityId:e,capability:r {snip}
  File "./src/app/services/device-manager/DeviceManagerService.ts", line 221, col 73, in h.<anonymous>
    device.watchedCapabilities.targetTemperature = await device.makeCapabilityInstance<number>(CapabilityType.TargetTemperature, (evt) => {
  ?, in Generator.next
  File "./node_modules/tslib/tslib.es6.js", line 71, col 1, in null.<anonymous>
    step((generator = generator.apply(thisArg, _arguments || [])).next());
  ?, in new Promise
  File "./node_modules/tslib/tslib.es6.js", line 67, col 1, in device
    return new (P || (P = Promise))(function (resolve, reject) {
  File "./src/app/services/device-manager/DeviceManagerService.ts", line 213, col 34, in apply
    private async attachWatchers(device: AuditedDevice) {

@WeeJeWel Will the device.update run, once the device gets ready?