Skip to content

Commit

Permalink
Merge pull request #32 from Luligu/dev
Browse files Browse the repository at this point in the history
Release 2.1.2
  • Loading branch information
Luligu committed Jun 21, 2024
2 parents 4c9e2d5 + 263b9bd commit 861e400
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## [2.1.2] - 2024-06-21

### Added

- [dependencies]: Update dependencies.
- [start]: Refactor start sequence.

<a href="https://www.buymeacoffee.com/luligugithub">
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
</a>

## [2.1.1] - 2024-06-20

### Added
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Luligu
14 changes: 10 additions & 4 deletions matterbridge-zigbee2mqtt.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"title": "Matterbridge zigbee2mqtt plugin",
"description": "matterbridge-zigbee2mqtt v. 2.0.17 by https://github.com/Luligu",
"type": "object",
"required": ["host", "port", "topic"],
"required": [
"host",
"port",
"topic"
],
"properties": {
"name": {
"description": "Plugin name",
Expand Down Expand Up @@ -88,11 +92,13 @@
},
"debug": {
"description": "Enable the debug for the plugin (development only)",
"type": "boolean"
"type": "boolean",
"default": false
},
"unregisterOnShutdown": {
"description": "Unregister all devices on shutdown (development only)",
"type": "boolean"
"type": "boolean",
"default": false
}
}
}
}
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matterbridge-zigbee2mqtt",
"version": "2.1.1",
"version": "2.1.2",
"description": "Matterbridge zigbee2mqtt plugin",
"author": "https://github.com/Luligu",
"license": "Apache-2.0",
Expand Down Expand Up @@ -92,15 +92,15 @@
"@eslint/js": "^9.5.0",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.6",
"@types/node": "^20.14.7",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"ts-jest": "^29.1.5",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"typescript-eslint": "^7.13.1"
}
}
24 changes: 21 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { BridgedDeviceBasicInformationCluster, DoorLock, DoorLockCluster, Matterbridge, MatterbridgeDevice, MatterbridgeDynamicPlatform, PlatformConfig, waiter } from 'matterbridge';
import { AnsiLogger, dn, gn, db, wr, zb, payloadStringify, rs, debugStringify } from 'node-ansi-logger';
import { AnsiLogger, dn, gn, db, wr, zb, payloadStringify, rs, debugStringify, CYAN } from 'node-ansi-logger';

import { ZigbeeDevice, ZigbeeEntity, ZigbeeGroup, BridgedBaseDevice } from './entity.js';
import { Zigbee2MQTT } from './zigbee2mqtt.js';
Expand Down Expand Up @@ -73,7 +73,7 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
constructor(matterbridge: Matterbridge, log: AnsiLogger, config: PlatformConfig) {
super(matterbridge, log, config);

this.debugEnabled = matterbridge.debugEnabled;
this.debugEnabled = config.debug as boolean;
this.shouldStart = false;
this.shouldConfigure = false;

Expand Down Expand Up @@ -104,6 +104,8 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
this.log.debug('Created ZigbeePlatform as Matterbridge extension');
return;
}

this.log.info(`Initializing platform: ${this.config.name}${rs} v${CYAN}${this.version}`);
this.log.info(`Loaded zigbee2mqtt parameters from ${path.join(matterbridge.matterbridgeDirectory, 'matterbridge-zigbee2mqtt.config.json')}${rs}:`);
// this.log.debug(`Config:')}${rs}`, config);

Expand Down Expand Up @@ -272,6 +274,7 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
this.z2mDevicesRegistered = true;
}
}

if (this.shouldConfigure) {
this.log.info(`Configuring ${this.zigbeeEntities.length} zigbee entities.`);
for (const bridgedEntity of this.zigbeeEntities) {
Expand All @@ -286,6 +289,7 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
this.z2m.on('bridge-groups', async (groups: BridgeGroup[]) => {
this.log.info(`zigbee2MQTT sent ${groups.length} groups ${this.z2mGroupsRegistered ? 'already registered' : ''}`);
this.z2mBridgeGroups = groups;

if (this.shouldStart) {
if (!this.z2mGroupsRegistered && this.z2mBridgeGroups) {
for (const group of this.z2mBridgeGroups) {
Expand All @@ -294,6 +298,7 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
this.z2mGroupsRegistered = true;
}
}

if (this.shouldConfigure) {
this.log.info(`Configuring ${this.zigbeeEntities.length} zigbee entities.`);
for (const bridgedEntity of this.zigbeeEntities) {
Expand All @@ -318,14 +323,16 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
const hasDevices = await waiter('z2mBridgeDevices & z2mBridgeGroups', () => this.z2mBridgeDevices !== undefined || this.z2mBridgeGroups !== undefined);

if (!hasOnline || !hasInfo || !hasDevices) {
this.log.error('Exiting due to missing zigbee2mqtt bridge state or info or devices/groups. Check if zigbee2mqtt is running and connected to the MQTT broker.');
this.log.error('The plugin did not receive zigbee2mqtt bridge state or info or devices/groups. Check if zigbee2mqtt is running and connected to the MQTT broker.');
return;
}

/*
if (!this.z2mDevicesRegistered || !this.z2mGroupsRegistered) {
this.shouldStart = true;
this.log.debug('Setting flag to start when zigbee2mqtt sends devices: ', reason);
}
*/

if (!this.z2mDevicesRegistered && this.z2mBridgeDevices) {
this.log.info(`Registering ${this.z2mBridgeDevices.length} devices`);
Expand All @@ -347,10 +354,12 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
}

override async onConfigure() {
/*
if (!this.z2mDevicesRegistered || !this.z2mGroupsRegistered) {
this.shouldConfigure = true;
this.log.debug('Setting flag to configure when zigbee2mqtt sends devices');
}
*/

this.log.info(`Configuring ${this.zigbeeEntities.length} zigbee entities.`);
for (const bridgedEntity of this.zigbeeEntities) {
Expand Down Expand Up @@ -404,10 +413,16 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
this.publishCallBack = undefined;
}

/**
* @deprecated
*/
public setPublishCallBack(onPublish: (entityName: string, topic: string, message: string) => Promise<void>): void {
this.publishCallBack = onPublish;
}

/**
* @deprecated
*/
public setPermitJoinCallBack(onPermitJoin: (entityName: string, permit: boolean) => Promise<void>): void {
this.permitJoinCallBack = onPermitJoin;
}
Expand All @@ -422,6 +437,9 @@ export class ZigbeePlatform extends MatterbridgeDynamicPlatform {
}
}

/**
* @deprecated
*/
public emit(eventName: string, data: Payload) {
this.z2m.emit(eventName, data);
}
Expand Down

0 comments on commit 861e400

Please sign in to comment.