matterbridge 2.1.5-dev.1 → 2.1.5-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import { AnsiLogger, BLUE, CYAN, YELLOW, db, debugStringify, er, hk, or, zb } fr
|
|
|
2
2
|
import { bridgedNode } from './matterbridgeDeviceTypes.js';
|
|
3
3
|
import { isValidNumber, isValidObject } from './utils/utils.js';
|
|
4
4
|
import { MatterbridgeBehavior, MatterbridgeBehaviorDevice, MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, MatterbridgeSwitchServer, } from './matterbridgeBehaviors.js';
|
|
5
|
-
import { addClusterServers, addFixedLabel, addOptionalClusterServers, addRequiredClusterServers, addUserLabel, capitalizeFirstLetter, createUniqueId, getBehavior, getBehaviourTypesFromClusterClientIds, getBehaviourTypesFromClusterServerIds, getDefaultFlowMeasurementClusterServer, getDefaultIlluminanceMeasurementClusterServer, getDefaultPressureMeasurementClusterServer, getDefaultRelativeHumidityMeasurementClusterServer, getDefaultTemperatureMeasurementClusterServer, getDefaultOccupancySensingClusterServer, lowercaseFirstLetter, updateAttribute, getClusterId, getAttributeId, setAttribute, getAttribute, checkNotLatinCharacters, generateUniqueId, } from './matterbridgeEndpointHelpers.js';
|
|
5
|
+
import { addClusterServers, addFixedLabel, addOptionalClusterServers, addRequiredClusterServers, addUserLabel, capitalizeFirstLetter, createUniqueId, getBehavior, getBehaviourTypesFromClusterClientIds, getBehaviourTypesFromClusterServerIds, getDefaultFlowMeasurementClusterServer, getDefaultIlluminanceMeasurementClusterServer, getDefaultPressureMeasurementClusterServer, getDefaultRelativeHumidityMeasurementClusterServer, getDefaultTemperatureMeasurementClusterServer, getDefaultOccupancySensingClusterServer, lowercaseFirstLetter, updateAttribute, getClusterId, getAttributeId, setAttribute, getAttribute, checkNotLatinCharacters, generateUniqueId, subscribeAttribute, } from './matterbridgeEndpointHelpers.js';
|
|
6
6
|
import { Endpoint, Lifecycle, MutableEndpoint, NamedHandler, SupportedBehaviors, VendorId } from '@matter/main';
|
|
7
7
|
import { getClusterNameById, MeasurementType } from '@matter/main/types';
|
|
8
8
|
import { Descriptor } from '@matter/main/clusters/descriptor';
|
|
@@ -130,7 +130,7 @@ export class MatterbridgeEndpoint extends Endpoint {
|
|
|
130
130
|
}
|
|
131
131
|
else
|
|
132
132
|
this.deviceTypes.set(firstDefinition.code, firstDefinition);
|
|
133
|
-
this.log = new AnsiLogger({ logName: 'MatterbridgeEndpoint', logTimestampFormat: 4, logLevel: debug === true ? "debug" : MatterbridgeEndpoint.logLevel });
|
|
133
|
+
this.log = new AnsiLogger({ logName: options.uniqueStorageKey ?? 'MatterbridgeEndpoint', logTimestampFormat: 4, logLevel: debug === true ? "debug" : MatterbridgeEndpoint.logLevel });
|
|
134
134
|
this.log.debug(`${YELLOW}new${db} MatterbridgeEndpoint: ${zb}${'0x' + firstDefinition.code.toString(16).padStart(4, '0')}${db}-${zb}${firstDefinition.name}${db} ` +
|
|
135
135
|
`id: ${CYAN}${options.uniqueStorageKey}${db} number: ${CYAN}${options.endpointId}${db} taglist: ${CYAN}${options.tagList ? debugStringify(options.tagList) : 'undefined'}${db}`);
|
|
136
136
|
this.behaviors.require(MatterbridgeBehavior, { deviceCommand: new MatterbridgeBehaviorDevice(this.log, this.commandHandler, undefined) });
|
|
@@ -171,24 +171,8 @@ export class MatterbridgeEndpoint extends Endpoint {
|
|
|
171
171
|
async updateAttribute(cluster, attribute, value, log) {
|
|
172
172
|
return await updateAttribute(this, cluster, attribute, value, log);
|
|
173
173
|
}
|
|
174
|
-
async subscribeAttribute(
|
|
175
|
-
|
|
176
|
-
if (this.construction.status !== Lifecycle.Status.Active) {
|
|
177
|
-
await this.construction.ready;
|
|
178
|
-
}
|
|
179
|
-
const events = this.events;
|
|
180
|
-
if (!(clusterName in events)) {
|
|
181
|
-
this.log.error(`subscribeAttribute ${hk}${attribute}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${this.maybeId}${er}:${or}${this.maybeNumber}${er}`);
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
attribute = lowercaseFirstLetter(attribute) + '$Changed';
|
|
185
|
-
if (!(attribute in events[clusterName])) {
|
|
186
|
-
this.log.error(`subscribeAttribute error: Attribute ${hk}${attribute}${er} not found on Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${this.maybeId}${er}:${or}${this.maybeNumber}${er}`);
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
events[clusterName][attribute].on(listener);
|
|
190
|
-
log?.info(`${db}Subscribed endpoint ${or}${this.id}${db}:${or}${this.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
|
|
191
|
-
return true;
|
|
174
|
+
async subscribeAttribute(cluster, attribute, listener, log) {
|
|
175
|
+
return await subscribeAttribute(this, cluster, attribute, listener, log);
|
|
192
176
|
}
|
|
193
177
|
async triggerEvent(clusterId, event, payload, log) {
|
|
194
178
|
const clusterName = lowercaseFirstLetter(getClusterNameById(clusterId));
|
|
@@ -207,6 +191,7 @@ export class MatterbridgeEndpoint extends Endpoint {
|
|
|
207
191
|
}
|
|
208
192
|
addClusterServers(serverList) {
|
|
209
193
|
addClusterServers(this, serverList);
|
|
194
|
+
return this;
|
|
210
195
|
}
|
|
211
196
|
async addFixedLabel(label, value) {
|
|
212
197
|
await addFixedLabel(this, label, value);
|
|
@@ -479,6 +479,26 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
|
|
|
479
479
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
480
480
|
return true;
|
|
481
481
|
}
|
|
482
|
+
export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
|
|
483
|
+
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
484
|
+
if (!clusterName) {
|
|
485
|
+
endpoint.log.error(`subscribeAttribute ${hk}${attribute}${er} error: cluster not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
if (endpoint.construction.status !== Lifecycle.Status.Active) {
|
|
489
|
+
endpoint.log.debug(`subscribeAttribute ${hk}${clusterName}.${attribute}${db}: Endpoint ${or}${endpoint.maybeId}${db}:${or}${endpoint.maybeNumber}${db} is in the ${BLUE}${endpoint.construction.status}${db} state`);
|
|
490
|
+
await endpoint.construction.ready;
|
|
491
|
+
}
|
|
492
|
+
const events = endpoint.events;
|
|
493
|
+
attribute = lowercaseFirstLetter(attribute) + '$Changed';
|
|
494
|
+
if (!(clusterName in events) || !(attribute in events[clusterName])) {
|
|
495
|
+
endpoint.log.error(`subscribeAttribute error: Attribute ${hk}${attribute.replace('$Changed', '')}${er} not found on Cluster ${'0x' + getClusterId(endpoint, clusterName)?.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
events[clusterName][attribute].on(listener);
|
|
499
|
+
log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
482
502
|
export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
|
|
483
503
|
return optionsFor(TemperatureMeasurementServer, {
|
|
484
504
|
measuredValue,
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { createWriteStream, statSync } from 'fs';
|
|
4
|
-
import { promises as fs } from 'fs';
|
|
5
|
-
import * as dns from 'dns';
|
|
6
3
|
import { AnsiLogger, idn, rs } from 'node-ansi-logger';
|
|
7
4
|
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
8
5
|
export function deepEqual(a, b, excludeProperties = []) {
|
|
@@ -263,6 +260,7 @@ export async function wait(timeout = 1000, name, debug = false) {
|
|
|
263
260
|
export async function createZip(outputPath, ...sourcePaths) {
|
|
264
261
|
const { default: archiver } = await import('archiver');
|
|
265
262
|
const { glob } = await import('glob');
|
|
263
|
+
const { createWriteStream, statSync } = await import('fs');
|
|
266
264
|
log.logLevel = "info";
|
|
267
265
|
log.logName = 'Archive';
|
|
268
266
|
log.debug(`creating archive ${outputPath} from ${sourcePaths.join(', ')} ...`);
|
|
@@ -328,6 +326,7 @@ export async function createZip(outputPath, ...sourcePaths) {
|
|
|
328
326
|
});
|
|
329
327
|
}
|
|
330
328
|
export async function copyDirectory(srcDir, destDir) {
|
|
329
|
+
const fs = await import('fs').then((mod) => mod.promises);
|
|
331
330
|
log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
|
|
332
331
|
try {
|
|
333
332
|
await fs.mkdir(destDir, { recursive: true });
|
|
@@ -350,6 +349,7 @@ export async function copyDirectory(srcDir, destDir) {
|
|
|
350
349
|
}
|
|
351
350
|
}
|
|
352
351
|
export async function resolveHostname(hostname, family = 4) {
|
|
352
|
+
const dns = await import('dns');
|
|
353
353
|
try {
|
|
354
354
|
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
355
355
|
return addresses.address;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge",
|
|
3
|
-
"version": "2.1.5-dev.
|
|
3
|
+
"version": "2.1.5-dev.2",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge",
|
|
9
|
-
"version": "2.1.5-dev.
|
|
9
|
+
"version": "2.1.5-dev.2",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@matter/main": "0.12.3",
|