Copyright © 2017,2018 Erik Baauw. All rights reserved.
While developing a number of homebridge plugins, I find myself duplicating a lot of code. The idea behind this utility library is to ease developing and maintaining homebridge plugins by separating this generic code, dealing with HomeKit and homebridge, from the specific code, dealing with the actual devices being exposed to HomeKit.
The homebridge-lib library provides the following functionality:
- Support for homebridge v2 dynamic platforms, including saving and restoring accessories from persistent storage between homebridge sessions;
- Universal Plug & Play (UPnP) device discovery;
- Setting up a heartbeat for device polling;
- Logging and error handling.
Technically, the homebridge-lib library is based on the following:
- Using promises rather than callback functions. The promises are provided by deferred;
- Using javascript classes rather than prototypes. An actual plugin extends the classes provided by homebridge-lib;
- Using events. In fact all homebridge-lib classes extend
EventEmitter
;
The homebridge-lib library provides a number of abstract superclasses, that act as delegate for homebridge platform plugins and for HomeKit accessories, services, and characteristics. A homebridge plugin based on homebridge-lib extends these classes, providing the device-specific logic.
See the Wiki for more information.
This library is not a homebridge plugin and should not be installed manually. Instead, homebridge plugins using this library should list it as a dependency in their package.json
. This way, npm
installs homebridge-lib automatically when installing the actual plugin.