devbridge
v0.1.0
Published
CLI tool to facilitate homebridge plugin development
Downloads
8
Readme
devbridge
Devbridge is a CLI tool that automates homebridge plugin development and allows you to quickly build and iterate your plugins during the development process.
Features
- Run and test multiple plugins – Devbridge provisions and starts Homebridge servers using a different username, pin code, and port per plugin.
- Plugin builds – Devbridge will a run your plugin's build script if one is present.
- Automated Homebridge Configuration – Devbridge keeps Homebridge config files isolated per plugin so you can run and test them in isolation.
- Debug with breakpoints – Devbridge allows you to set breakpoints for easy debugging with your favorite IDE.
Prerequisites
- node v9 or higher
- homebridge installed and available via your
PATH
Install
npm install -g devbridge
Configure Your Plugin
First you'll need to configure your plugin by creating a config.json
file under a directory named .devbridge
at the root of your plugin.
Alternatively, you can run devbridge init
to generate a sample config:
$ cd /dev/homebridge-plugin
$ devbridge init
✔ Create /dev/homebridge-plugin/.devbridge
✔ Write sample config /dev/homebridge-plugin/.devbridge/config.json
The generated config file looks like this:
{
"name": "homebridge-plugin",
"homebridge": {
"platform": "Plugin Name",
"someOption": "Any other config options your plugin requires"
}
}
This file will be used when generating the homebridge config file when running your plugin.
You must have either platform
or accessory
in your config, depending on which type of plugin it is. The value is the "pretty name" of your plugin. This is also where you would add other options that your plugin might use, such as username and password.
For example, the generated Homebridge config.json
file for a plugin with the above config would look like this:
{
"bridge": {
"name": "Devbridge",
"username": "FC:11:DE:D6:12:2D",
"port": 29893,
"pin": "461-73-439"
},
"platforms": [{
"platform": "Plugin Name",
"someOption": "Any other config options your plugin requires"
}],
"accessories": []
}
Building
Devbridge checks to see if the package.json
file in your plugin's directory contains a build
script. If one exists, Devbridge will use it to build your plugin.
The build process is skipped if there's no build
script.
Commands
Run
The run
command goes through the entire flow of checking your configuration, building your plugin, and starting a Homebridge server with your plugin loaded.
Available options can be found by using the --help
flag:
$ devbridge run --help
Usage: run [options]
Build a plugin and start a new homebridge server with the plugin config
Options:
-d, --debug Run in debug mode
-s, --skip-build Skip build process
-c, --clear Clear homebridge cache
-r, --refresh Apply new homebridge configuration
-h, --help output usage information
Debug with Breakpoints
Flag: -d
or --debug
This will start a Homebridge server using the Node remote debugger. You can attach to the debugger on port 9229
in an IDE that supports it, such as VS Code.
Skip build
Flag: -s
or --skip-build
Skips the build flow but still applies any necessary configuration and starts a Homebridge server.
Clear homebridge cache
Flag: -c
or --clear
Clear out the Homebridge cache and start a fresh server.
Refresh configuration
Flag: -r
or --refresh
Applies any new changes made to your .devbridge/config.json
file.
Example Run
$ devbridge run
✔ Checking plugin config
✔ Checking build script
✔ Building homebridge-coolplugin
✔ Found homebridge config
✔ Starting homebridge
[6/30/2018, 10:19:05 AM] Loaded config.json with 0 accessories and 1 platforms.
[6/30/2018, 10:19:05 AM] ---
[6/30/2018, 10:19:05 AM] Loaded plugin: homebridge-coolplugin
[6/30/2018, 10:19:05 AM] Registering platform 'homebridge-coolplugin.CoolPlugin'
[6/30/2018, 10:19:05 AM] ---
[6/30/2018, 10:19:05 AM] Loading 1 platforms...
[6/30/2018, 10:19:05 AM] [Sesame] Initializing CoolPlugin platform...
[6/30/2018, 10:19:05 AM] Loading 0 accessories...
Build
devbridge build
will only build your plugin and nothing else.
Example Build
$ devbridge build
✔ Checking plugin config
✔ Checking build script
✔ Building homebridge-coolplugin