Skip to content

Commit a38368b

Browse files
committed
First version
Add http interface to toggle buttons Fixes Add v1.1.0 Better logs Update characteristics asynchronous on toggle First stable release
1 parent ae59bc8 commit a38368b

File tree

9 files changed

+189
-337
lines changed

9 files changed

+189
-337
lines changed

.eslintrc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
"ecmaVersion": 2018,
1010
"sourceType": "module"
1111
},
12-
"ignorePatterns": [
13-
"dist"
14-
],
12+
"ignorePatterns": ["dist"],
1513
"rules": {
16-
"quotes": ["warn", "single"],
1714
"indent": ["warn", 2, { "SwitchCase": 1 }],
1815
"semi": ["off"],
19-
"comma-dangle": ["warn", "always-multiline"],
2016
"dot-notation": "off",
2117
"eqeqeq": "warn",
2218
"curly": ["warn", "all"],
@@ -28,7 +24,11 @@
2824
"comma-spacing": ["error"],
2925
"no-multi-spaces": ["warn", { "ignoreEOLComments": true }],
3026
"no-trailing-spaces": ["warn"],
31-
"lines-between-class-members": ["warn", "always", {"exceptAfterSingleLine": true}],
27+
"lines-between-class-members": [
28+
"warn",
29+
"always",
30+
{ "exceptAfterSingleLine": true }
31+
],
3232
"@typescript-eslint/explicit-function-return-type": "off",
3333
"@typescript-eslint/no-non-null-assertion": "off",
3434
"@typescript-eslint/explicit-module-boundary-types": "off",

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"files.eol": "\n",
33
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": true
4+
"source.fixAll.eslint": "explicit"
55
},
6-
"editor.rulers": [ 140 ],
6+
"editor.rulers": [140],
77
"eslint.enable": true
8-
}
8+
}

README.md

Lines changed: 3 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,5 @@
1-
<p align="center">
1+
# Homebridge Virtual Button
22

3-
<img src="https://github.com/homebridge/branding/raw/latest/logos/homebridge-wordmark-logo-vertical.png" width="150">
3+
This plugin let you create virtual buttons without any hardware behind it. It will also offer an http interface to toggle these buttons. This is nice to make all kinds of complex automations possible.
44

5-
</p>
6-
7-
<span align="center">
8-
9-
# Homebridge Platform Plugin Template
10-
11-
</span>
12-
13-
This is a template Homebridge dynamic platform plugin and can be used as a base to help you get started developing your own plugin.
14-
15-
This template should be used in conjunction with the [developer documentation](https://developers.homebridge.io/). A full list of all supported service types, and their characteristics is available on this site.
16-
17-
### Clone As Template
18-
19-
Click the link below to create a new GitHub Repository using this template, or click the *Use This Template* button above.
20-
21-
<span align="center">
22-
23-
### [Create New Repository From Template](https://github.com/homebridge/homebridge-plugin-template/generate)
24-
25-
</span>
26-
27-
### Setup Development Environment
28-
29-
To develop Homebridge plugins you must have Node.js 18 or later installed, and a modern code editor such as [VS Code](https://code.visualstudio.com/). This plugin template uses [TypeScript](https://www.typescriptlang.org/) to make development easier and comes with pre-configured settings for [VS Code](https://code.visualstudio.com/) and ESLint. If you are using VS Code install these extensions:
30-
31-
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
32-
33-
### Install Development Dependencies
34-
35-
Using a terminal, navigate to the project folder and run this command to install the development dependencies:
36-
37-
```shell
38-
$ npm install
39-
```
40-
41-
### Update package.json
42-
43-
Open the [`package.json`](./package.json) and change the following attributes:
44-
45-
- `name` - this should be prefixed with `homebridge-` or `@username/homebridge-`, is case-sensitive, and contains no spaces nor special characters apart from a dash `-`
46-
- `displayName` - this is the "nice" name displayed in the Homebridge UI
47-
- `repository.url` - Link to your GitHub repo
48-
- `bugs.url` - Link to your GitHub repo issues page
49-
50-
When you are ready to publish the plugin you should set `private` to false, or remove the attribute entirely.
51-
52-
### Update Plugin Defaults
53-
54-
Open the [`src/settings.ts`](./src/settings.ts) file and change the default values:
55-
56-
- `PLATFORM_NAME` - Set this to be the name of your platform. This is the name of the platform that users will use to register the plugin in the Homebridge `config.json`.
57-
- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file.
58-
59-
Open the [`config.schema.json`](./config.schema.json) file and change the following attribute:
60-
61-
- `pluginAlias` - set this to match the `PLATFORM_NAME` you defined in the previous step.
62-
63-
### Build Plugin
64-
65-
TypeScript needs to be compiled into JavaScript before it can run. The following command will compile the contents of your [`src`](./src) directory and put the resulting code into the `dist` folder.
66-
67-
```shell
68-
$ npm run build
69-
```
70-
71-
### Link To Homebridge
72-
73-
Run this command so your global installation of Homebridge can discover the plugin in your development environment:
74-
75-
```shell
76-
$ npm link
77-
```
78-
79-
You can now start Homebridge, use the `-D` flag, so you can see debug log messages in your plugin:
80-
81-
```shell
82-
$ homebridge -D
83-
```
84-
85-
### Watch For Changes and Build Automatically
86-
87-
If you want to have your code compile automatically as you make changes, and restart Homebridge automatically between changes, you first need to add your plugin as a platform in `~/.homebridge/config.json`:
88-
```
89-
{
90-
...
91-
"platforms": [
92-
{
93-
"name": "Config",
94-
"port": 8581,
95-
"platform": "config"
96-
},
97-
{
98-
"name": "<PLUGIN_NAME>",
99-
//... any other options, as listed in config.schema.json ...
100-
"platform": "<PLATFORM_NAME>"
101-
}
102-
]
103-
}
104-
```
105-
106-
and then you can run:
107-
108-
```shell
109-
$ npm run watch
110-
```
111-
112-
This will launch an instance of Homebridge in debug mode which will restart every time you make a change to the source code. It will load the config stored in the default location under `~/.homebridge`. You may need to stop other running instances of Homebridge while using this command to prevent conflicts. You can adjust the Homebridge startup command in the [`nodemon.json`](./nodemon.json) file.
113-
114-
### Customise Plugin
115-
116-
You can now start customising the plugin template to suit your requirements.
117-
118-
- [`src/platform.ts`](./src/platform.ts) - this is where your device setup and discovery should go.
119-
- [`src/platformAccessory.ts`](./src/platformAccessory.ts) - this is where your accessory control logic should go, you can rename or create multiple instances of this file for each accessory type you need to implement as part of your platform plugin. You can refer to the [developer documentation](https://developers.homebridge.io/) to see what characteristics you need to implement for each service type.
120-
- [`config.schema.json`](./config.schema.json) - update the config schema to match the config you expect from the user. See the [Plugin Config Schema Documentation](https://developers.homebridge.io/#/config-schema).
121-
122-
### Versioning Your Plugin
123-
124-
Given a version number `MAJOR`.`MINOR`.`PATCH`, such as `1.4.3`, increment the:
125-
126-
1. **MAJOR** version when you make breaking changes to your plugin,
127-
2. **MINOR** version when you add functionality in a backwards compatible manner, and
128-
3. **PATCH** version when you make backwards compatible bug fixes.
129-
130-
You can use the `npm version` command to help you with this:
131-
132-
```shell
133-
# major update / breaking changes
134-
$ npm version major
135-
136-
# minor update / new features
137-
$ npm version update
138-
139-
# patch / bugfixes
140-
$ npm version patch
141-
```
142-
143-
### Publish Package
144-
145-
When you are ready to publish your plugin to [npm](https://www.npmjs.com/), make sure you have removed the `private` attribute from the [`package.json`](./package.json) file then run:
146-
147-
```shell
148-
$ npm publish
149-
```
150-
151-
If you are publishing a scoped plugin, i.e. `@username/homebridge-xxx` you will need to add `--access=public` to command the first time you publish.
152-
153-
#### Publishing Beta Versions
154-
155-
You can publish *beta* versions of your plugin for other users to test before you release it to everyone.
156-
157-
```shell
158-
# create a new pre-release version (eg. 2.1.0-beta.1)
159-
$ npm version prepatch --preid beta
160-
161-
# publish to @beta
162-
$ npm publish --tag=beta
163-
```
164-
165-
Users can then install the *beta* version by appending `@beta` to the install command, for example:
166-
167-
```shell
168-
$ sudo npm install -g homebridge-example-plugin@beta
169-
```
170-
171-
### Best Practices
172-
Consider creating your plugin with the [Homebridge Verified](https://github.com/homebridge/verified) criteria in mind. This will help you to create a plugin that is easy to use and works well with Homebridge.
173-
You can then submit your plugin to the Homebridge Verified list for review.
174-
The most up-to-date criteria can be found [here](https://github.com/homebridge/verified#requirements).
175-
For reference, the current criteria are:
176-
177-
- The plugin must successfully install.
178-
- The plugin must implement the [Homebridge Plugin Settings GUI](https://github.com/oznu/homebridge-config-ui-x/wiki/Developers:-Plugin-Settings-GUI).
179-
- The plugin must not start unless it is configured.
180-
- The plugin must not execute post-install scripts that modify the users' system in any way.
181-
- The plugin must not contain any analytics or calls that enable you to track the user.
182-
- The plugin must not throw unhandled exceptions, the plugin must catch and log its own errors.
183-
- The plugin must be published to npm and the source code available on GitHub.
184-
- A GitHub release - with patch notes - should be created for every new version of your plugin.
185-
- The plugin must run on all [supported LTS versions of Node.js](https://github.com/homebridge/homebridge/wiki/How-To-Update-Node.js), at the time of writing this is Node.js v16 and v18.
186-
- The plugin must not require the user to run Homebridge in a TTY or with non-standard startup parameters, even for initial configuration.
187-
- If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory.
188-
189-
### Useful Links
190-
Note these links are here for help but are not supported/verified by the Homebridge team
191-
- [Custom Characteristics](https://github.com/homebridge/homebridge-plugin-template/issues/20)
5+
To toggle a button on the interface, call `http://homebridge.local:18082/toggle?name=NameOfMyButton`

config.schema.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
{
2-
"pluginAlias": "ExampleHomebridgePlugin",
2+
"pluginAlias": "HomebridgeVirtualButton",
33
"pluginType": "platform",
44
"singular": true,
55
"schema": {
66
"type": "object",
7+
"additionalProperties": true,
78
"properties": {
8-
"name": {
9-
"title": "Name",
10-
"type": "string",
11-
"required": true,
12-
"default": "Example Dynamic Platform"
9+
"switches": {
10+
"type": "array",
11+
"additionalItems": true,
12+
"items": {
13+
"type": "object",
14+
"additionalProperties": true,
15+
"properties": {
16+
"name": {
17+
"title": "Disply name for homekit",
18+
"type": "string",
19+
"required": true
20+
}
21+
}
22+
}
1323
}
1424
}
1525
}
16-
}
26+
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
2-
"private": true,
3-
"displayName": "Plugin Name",
4-
"name": "homebridge-plugin-name",
5-
"version": "1.0.0",
2+
"displayName": "Homebridge Virtual Button",
3+
"name": "homebridge-virtual-button",
4+
"version": "1.1.3",
65
"description": "A short description about what your plugin does.",
76
"license": "Apache-2.0",
87
"repository": {
98
"type": "git",
10-
"url": "https://github.com/USERNAME/GITHUB_PROJECT_NAME.git"
9+
"url": "https://github.com/rocket-monkey/homebridge-virtual-button.git"
1110
},
1211
"bugs": {
13-
"url": "https://github.com/USERNAME/GITHUB_PROJECT_NAME/issues"
12+
"url": "https://github.com/rocket-monkey/homebridge-virtual-button/issues"
1413
},
1514
"engines": {
1615
"node": "^18.17.0 || ^20.9.0",

0 commit comments

Comments
 (0)