Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
- Add homebridge-intercom plugin code
- Add publish workflow
- Change README
  • Loading branch information
denisgabriel5 committed Jun 17, 2024
1 parent c99720a commit 492dc36
Show file tree
Hide file tree
Showing 18 changed files with 760 additions and 856 deletions.
Binary file added .github/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Lint
name: Build

on: [push, pull_request]

Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish Node.js Package to npm

on:
release:
types:
- created

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm ci

- name: Lint the project
run: npm run lint

- name: Build the project
run: npm run build

- name: List, audit, fix outdated dependencies and build again
run: |
npm list --outdated
npm audit || true # ignore failures
npm audit fix || true
npm list --outdated
npm run build
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ dist

# Webstorm
.idea

.DS_Store
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files.eol": "\n",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"editor.rulers": [ 140 ],
"eslint.enable": true
Expand Down
213 changes: 53 additions & 160 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,191 +1,84 @@
<p align="center">

<img src="https://github.com/homebridge/branding/raw/latest/logos/homebridge-wordmark-logo-vertical.png" width="150">

<a href="https://homebridge.io"><img src="https://raw.githubusercontent.com/homebridge/branding/latest/logos/homebridge-color-round-stylized.png" height="140"></a>
</p>

<span align="center">

# Homebridge Platform Plugin Template

</span>

This is a template Homebridge dynamic platform plugin and can be used as a base to help you get started developing your own plugin.

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.
# Homebridge Intercom Plugin

### Clone As Template

Click the link below to create a new GitHub Repository using this template, or click the *Use This Template* button above.

<span align="center">

### [Create New Repository From Template](https://github.com/homebridge/homebridge-plugin-template/generate)
[![npm](https://badgen.net/npm/v/homebridge-intercom/latest)](https://www.npmjs.com/package/homebridge-intercom)
[![npm](https://badgen.net/npm/dt/homebridge-intercom?label=downloads)](https://www.npmjs.com/package/homebridge-intercom)
<a href="https://github.com/denisgabriel5/homebridge-intercom/actions/workflows/build.yml"><img title="Node Build" src="https://github.com/denisgabriel5/homebridge-intercom/actions/workflows/build.yml/badge.svg"></a>

</span>

### Setup Development Environment

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:

- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
## Overview

### Install Development Dependencies
**Homebridge Intercom** is a plugin for [Homebridge](https://github.com/homebridge/homebridge) that enables integration with old intercoms. This allows you to control and monitor your intercom system directly from your Home app.

Using a terminal, navigate to the project folder and run this command to install the development dependencies:
## Features

```shell
npm install
```

### Update package.json

Open the [`package.json`](./package.json) and change the following attributes:

- `name` - this should be prefixed with `homebridge-` or `@username/homebridge-`, is case-sensitive, and contains no spaces nor special characters apart from a dash `-`
- `displayName` - this is the "nice" name displayed in the Homebridge UI
- `repository.url` - Link to your GitHub repo
- `bugs.url` - Link to your GitHub repo issues page

When you are ready to publish the plugin you should set `private` to false, or remove the attribute entirely.

### Update Plugin Defaults
* **Notifications**: Receive notifications when someone rings your intercom.
* **Door control**: Unlock the door connected to your intercom.
* **Automations**: Create automatizations whne the intercom rings, via an Occupancy Sensor exposed in the Home app.

Open the [`src/settings.ts`](./src/settings.ts) file and change the default values:
## Installation Instructions

- `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`.
- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file.
If you have installed Homebridge UI, then you can install the plugin from the Homebridge Plugins screen by searching for `homebridge-intercom`. If not, then you can install it by running this command:

Open the [`config.schema.json`](./config.schema.json) file and change the following attribute:

- `pluginAlias` - set this to match the `PLATFORM_NAME` you defined in the previous step.

### Build Plugin

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.

```shell
npm run build
```

### Link To Homebridge

Run this command so your global installation of Homebridge can discover the plugin in your development environment:

```shell
npm link
```

You can now start Homebridge, use the `-D` flag, so you can see debug log messages in your plugin:

```shell
homebridge -D
```

### Watch For Changes and Build Automatically

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`:
```
{
...
"platforms": [
{
"name": "Config",
"port": 8581,
"platform": "config"
},
{
"name": "<PLUGIN_NAME>",
//... any other options, as listed in config.schema.json ...
"platform": "<PLATFORM_NAME>"
}
]
}
```

and then you can run:

```shell
npm run watch
sudo npm install -g homebridge-intercom
```

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.
## Usage

### Customise Plugin
### Configuration

You can now start customising the plugin template to suit your requirements.
In order to configure the intercom you will need to fill the following fields:

- [`src/platform.ts`](./src/platform.ts) - this is where your device setup and discovery should go.
- [`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.
- [`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).
#### Intercom general fields:

### Versioning Your Plugin
- Name: `string` _(required)_
- The name that will appear in your homebridge log.
- Manufacturer: `string` _(optional)_
- What will show under Manufacturer in accessory settings.
- Model: `string` _(optional)_
- What will show under Model in accessory settings.
- Serial Number: `string` _(optional)_
- What will show under Serial Number in accessory settings.
- Timeout: `number` _(optional)_
- The number of seconds between the unlocking and locking notifications. Defaults to 10 seconds.
- Intercom type: `string` _(required)_
- The intercom communication with Homebridge is done directly with the intercom or indirectly. When done indirectly, an interface will be used, such as Raspberry Pi or Shelly.
As of now, these are the supported ways of communication:
- Shelly Uni _(indirectly)_

Given a version number `MAJOR`.`MINOR`.`PATCH`, such as `1.4.3`, increment the:
_Note: Please open an issue if you would like support added for your intercom._

1. **MAJOR** version when you make breaking changes to your plugin,
2. **MINOR** version when you add functionality in a backwards compatible manner, and
3. **PATCH** version when you make backwards compatible bug fixes.
#### Intercom specific fields:
1. Shelly Uni:
- Status Url: `string` _(required)_
- URL which retrives the status of the Shelly Uni
- Talk Url: `string` _(required)_
- URL which triggers Talk button on the Shelly Uni.
- Open Url: `string` _(required)_
- URL which triggers Open button on the Shelly Uni.
- Buttons timeout: `number` _(optional)_
- The number of seconds between _pressing_ the Talk button and Open button. Defaults to 1 second.

You can use the `npm version` command to help you with this:
### Description

```shell
# major update / breaking changes
npm version major
Once configured, your intercom system will be accessible through the Home app.

# minor update / new features
npm version update
You will have one accessory (the Intercom) which will encompass 3 accessories:
- 1 Doorbell;
- 1 Locking Mechanism;
- 1 Occupancy Sensor (this will be useful in automations to detect when the Intercom is ringing).

# patch / bugfixes
npm version patch
```
When someone will ring the intercom, the Doorbell will sent a notifications to all your Apple devices. Then to open the door, you will have to use the unlock switch, which is present in the Intercom accessory.

### Publish Package
If you want you can automatize the opening of the door by using the Occupancy Sensor. This sensor will get triggered everytime the Intercom rings. You will still get the ringing notification, as well as unlocking/locking the door notifications.

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:

```shell
npm publish
```

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.

#### Publishing Beta Versions

You can publish *beta* versions of your plugin for other users to test before you release it to everyone.

```shell
# create a new pre-release version (eg. 2.1.0-beta.1)
npm version prepatch --preid beta

# publish to @beta
npm publish --tag=beta
```

Users can then install the *beta* version by appending `@beta` to the install command, for example:

```shell
sudo npm install -g homebridge-example-plugin@beta
```
## License

### Best Practices
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.
You can then submit your plugin to the Homebridge Verified list for review.
The most up-to-date criteria can be found [here](https://github.com/homebridge/verified#requirements).
For reference, the current criteria are:

- The plugin must successfully install.
- The plugin must implement the [Homebridge Plugin Settings GUI](https://github.com/oznu/homebridge-config-ui-x/wiki/Developers:-Plugin-Settings-GUI).
- The plugin must not start unless it is configured.
- The plugin must not execute post-install scripts that modify the users' system in any way.
- The plugin must not contain any analytics or calls that enable you to track the user.
- The plugin must not throw unhandled exceptions, the plugin must catch and log its own errors.
- The plugin must be published to npm and the source code available on GitHub.
- A GitHub release - with patch notes - should be created for every new version of your plugin.
- 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.
- The plugin must not require the user to run Homebridge in a TTY or with non-standard startup parameters, even for initial configuration.
- If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory.

### Useful Links
Note these links are here for help but are not supported/verified by the Homebridge team
- [Custom Characteristics](https://github.com/homebridge/homebridge-plugin-template/issues/20)
This project is licensed under the Apache-2.0 license - see the [LICENSE](LICENSE) file for details.
Loading

0 comments on commit 492dc36

Please sign in to comment.