Skip to content

Latest commit

 

History

History
192 lines (113 loc) · 6.16 KB

README-DEV.md

File metadata and controls

192 lines (113 loc) · 6.16 KB

Matterbridge Logo   Matterbridge

npm version npm downloads Docker Version Docker Pulls Node.js CI

power by power by power by


Development

Guidelines on imports/exports

Matterbridge exports from:

"matterbridge"

  • Matterbridge and all Matterbridge related classes.
  • All relevant matter-node.js or matter.js clusters, classes and functions.

"matterbridge/matter"

  • All relevant matter.js new api only exports (in beta).

"matterbridge/cluster"

  • All clusters not present in matter.js or modified.

"matterbridge/utils"

  • All general utils and colorUtils functions.

"matterbridge/logger"

  • AnsiLogger class.

"matterbridge/storage"

  • NodeStorageManager and NodeStorage classes.

******

A plugin must never install or import from @matter or @project-chip directly (neither as a dependency, devDependency, nor peerDependency), as this leads to a second instance of matter.js, causing instability and unpredictable errors such as "The only instance is Endpoint".

Additionally, when Matterbridge updates the matter.js version, it should be consistent across all plugins.

******

A plugin must never install Matterbridge (neither as a dependency, devDependency, nor peerDependency).

Matterbridge must be linked to the plugin in development only.

"scripts": {
    '''
    "dev:link": "npm link matterbridge",
    '''
}

******

I added some error messages when a plugin has wrong imports or configurations and the plugin will be disabled to prevent instability and crashes.

Migration to matter.js V8

I'm working with matter.js team to define the strategy for the migration of Matterbridge to the new API.

  • First phase: crete MatterbridgeEdge class: completed 90%
  • Second phase: create MatterbridgeEndpoint and MatterbridgeBehaviors classes: completed 90%
  • Third phase: modifiy all plugins to support both normal and edge mode of Matterbridge: completed 80%
  • Fourth phase: remove all old api code from Matterbridge and all plugins...

How to create your plugin

The easiest way is to clone:

Then change the name (keep matterbridge- at the beginning of the name), version, description and author in the package.json.

Add your plugin logic in platform.ts.

How to install and register a plugin for development (from github)

To install i.e. https://github.com/Luligu/matterbridge-example-accessory-platform

On windows:

cd $HOME\Matterbridge

On linux:

cd ~/Matterbridge

then clone the plugin

git clone https://github.com/Luligu/matterbridge-example-accessory-platform
cd matterbridge-example-accessory-platform
npm install
npm run build

then add the plugin to Matterbridge

matterbridge -add .\

MatterbridgeDynamicPlatform and MatterbridgeAccessoryPlatform api

public name: string

The plugin name.

public type: string

The plugin platform type.

public config: object

The plugin config (loaded before the platform constructor is called and saved after onShutdown() is called). Here you can store your plugin configuration (see matterbridge-zigbee2mqtt for example)

async onStart(reason?: string)

The method onStart() is where you have to create your MatterbridgeDevice and add all needed clusters and command handlers.

The MatterbridgeDevice class has the create cluster methods already done and all command handlers needed (see plugin examples).

The method is called when Matterbridge load the plugin.

async onConfigure()

The method onConfigure() is where you can configure or initialize your device.

The method is called when the platform is commissioned.

async onShutdown(reason?: string)

The method onShutdown() is where you have to eventually cleanup some resources.

The method is called when Matterbridge is shutting down.

async registerDevice(device: MatterbridgeDevice)

After you created your device, add it to the platform.

async unregisterDevice(device: MatterbridgeDevice)

You can unregister one or more device.

async unregisterAllDevices()

You can unregister all devices you added.

It can be useful to call this method from onShutdown() if you don't want to keep all the devices during development.

MatterbridgeDevice api

Work in progress...

Contribution Guidelines

Thank you for your interest in contributing to my project!

I warmly welcome contributions to this project! Whether it's reporting bugs, proposing new features, updating documentation, or writing code, your help is greatly appreciated.

Getting Started

  • Fork this repository to your own GitHub account and clone it to your local device.
  • Make the necessary changes and test them out
  • Commit your changes and push to your forked repository

Submitting Changes

  • Create a new pull request against the dev from my repository and I'll be glad to check it out
  • Be sure to follow the existing code style
  • Add unit tests for any new or changed functionality if possible
  • In your pull request, do describe what your changes do and how they work