naofireblade / homebridge-neato

A Neato vacuum robot plugin for homebridge.
MIT License
69 stars 18 forks source link

Localization and Modularization of TS Plugin #66

Closed himbeles closed 3 years ago

himbeles commented 3 years ago

Add localization as in #65, but for the TS variant of the plugin:

In this context, I have restructured the plugin a bit to be a bit more modular. Note that I have unified getSwitchService and getOccupancyService into one registerService function with an optional list of added characteristic handlers as an argument. Getting the Services is now done via this.accessory.getServiceById(serviceType, serviceName) instead of this.accessory.getService(displayName) to not rely on the display name for service identification.

naofireblade commented 3 years ago

Thanks for providing this PR!

naofireblade commented 3 years ago

Binding this at once for all handlers is not working for me. The plugin throws these errors as soon as a handler gets called.

This plugin threw an error from the characteristic 'On': Unhandled error thrown inside read handler for characteristic: Cannot read property 'eco' of undefined. See https://git.io/JtMGR for more info.
[5/10/2021, 7:12:54 PM] [homebridge-neato] TypeError: Cannot read property 'eco' of undefined
    at On.getEco [as getHandler] (/Users/arne/Projekte/homebridge/homebridge-neato/src/accessories/NeatoVacuumRobot.ts:469:23)
    at On.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1450:32)
    at step (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
    at Object.next (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:124:57)
    at /usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:113:16)
    at On.Characteristic.handleGetRequest (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:656:24)
    at Bridge.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:1508:27)
    at step (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
naofireblade commented 3 years ago

I re-added the binding on each handler