From 5e193c2db56ba0e8177b091d0fb5eefa0d62f7a9 Mon Sep 17 00:00:00 2001 From: Luligu <132135057+Luligu@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:59:23 +0200 Subject: [PATCH] V8 --- package-lock.json | 110 ++++++++++++++++++------------------ package.json | 6 +- src/matterbridgeDeviceV8.ts | 37 +++++------- src/matterbridgeV8.ts | 49 ++++++++++++---- 4 files changed, 111 insertions(+), 91 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd192b3d..c723d95e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "matterbridge", - "version": "1.3.7", + "version": "1.3.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "matterbridge", - "version": "1.3.7", + "version": "1.3.8", "license": "Apache-2.0", "dependencies": { "@project-chip/matter-node.js": "^0.9.3", @@ -35,8 +35,8 @@ "prettier": "^3.3.2", "rimraf": "^5.0.7", "ts-jest": "^29.1.5", - "typescript": "^5.5.2", - "typescript-eslint": "^7.14.1" + "typescript": "^5.5.3", + "typescript-eslint": "^7.15.0" }, "engines": { "node": ">=18.0.0" @@ -1897,17 +1897,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.14.1.tgz", - "integrity": "sha512-aAJd6bIf2vvQRjUG3ZkNXkmBpN+J7Wd0mfQiiVCJMu9Z5GcZZdcc0j8XwN/BM97Fl7e3SkTXODSk4VehUv7CGw==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.15.0.tgz", + "integrity": "sha512-uiNHpyjZtFrLwLDpHnzaDlP3Tt6sGMqTCiqmxaN4n4RP0EfYZDODJyddiFDF44Hjwxr5xAcaYxVKm9QKQFJFLA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.14.1", - "@typescript-eslint/type-utils": "7.14.1", - "@typescript-eslint/utils": "7.14.1", - "@typescript-eslint/visitor-keys": "7.14.1", + "@typescript-eslint/scope-manager": "7.15.0", + "@typescript-eslint/type-utils": "7.15.0", + "@typescript-eslint/utils": "7.15.0", + "@typescript-eslint/visitor-keys": "7.15.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -1931,16 +1931,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.14.1.tgz", - "integrity": "sha512-8lKUOebNLcR0D7RvlcloOacTOWzOqemWEWkKSVpMZVF/XVcwjPR+3MD08QzbW9TCGJ+DwIc6zUSGZ9vd8cO1IA==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.15.0.tgz", + "integrity": "sha512-k9fYuQNnypLFcqORNClRykkGOMOj+pV6V91R4GO/l1FDGwpqmSwoOQrOHo3cGaH63e+D3ZiCAOsuS/D2c99j/A==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "7.14.1", - "@typescript-eslint/types": "7.14.1", - "@typescript-eslint/typescript-estree": "7.14.1", - "@typescript-eslint/visitor-keys": "7.14.1", + "@typescript-eslint/scope-manager": "7.15.0", + "@typescript-eslint/types": "7.15.0", + "@typescript-eslint/typescript-estree": "7.15.0", + "@typescript-eslint/visitor-keys": "7.15.0", "debug": "^4.3.4" }, "engines": { @@ -1985,14 +1985,14 @@ "license": "MIT" }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.14.1.tgz", - "integrity": "sha512-gPrFSsoYcsffYXTOZ+hT7fyJr95rdVe4kGVX1ps/dJ+DfmlnjFN/GcMxXcVkeHDKqsq6uAcVaQaIi3cFffmAbA==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.15.0.tgz", + "integrity": "sha512-Q/1yrF/XbxOTvttNVPihxh1b9fxamjEoz2Os/Pe38OHwxC24CyCqXxGTOdpb4lt6HYtqw9HetA/Rf6gDGaMPlw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.14.1", - "@typescript-eslint/visitor-keys": "7.14.1" + "@typescript-eslint/types": "7.15.0", + "@typescript-eslint/visitor-keys": "7.15.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -2003,14 +2003,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.14.1.tgz", - "integrity": "sha512-/MzmgNd3nnbDbOi3LfasXWWe292+iuo+umJ0bCCMCPc1jLO/z2BQmWUUUXvXLbrQey/JgzdF/OV+I5bzEGwJkQ==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.15.0.tgz", + "integrity": "sha512-SkgriaeV6PDvpA6253PDVep0qCqgbO1IOBiycjnXsszNTVQe5flN5wR5jiczoEoDEnAqYFSFFc9al9BSGVltkg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "7.14.1", - "@typescript-eslint/utils": "7.14.1", + "@typescript-eslint/typescript-estree": "7.15.0", + "@typescript-eslint/utils": "7.15.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -2056,9 +2056,9 @@ "license": "MIT" }, "node_modules/@typescript-eslint/types": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.14.1.tgz", - "integrity": "sha512-mL7zNEOQybo5R3AavY+Am7KLv8BorIv7HCYS5rKoNZKQD9tsfGUpO4KdAn3sSUvTiS4PQkr2+K0KJbxj8H9NDg==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.15.0.tgz", + "integrity": "sha512-aV1+B1+ySXbQH0pLK0rx66I3IkiZNidYobyfn0WFsdGhSXw+P3YOqeTq5GED458SfB24tg+ux3S+9g118hjlTw==", "dev": true, "license": "MIT", "engines": { @@ -2070,14 +2070,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.14.1.tgz", - "integrity": "sha512-k5d0VuxViE2ulIO6FbxxSZaxqDVUyMbXcidC8rHvii0I56XZPv8cq+EhMns+d/EVIL41sMXqRbK3D10Oza1bbA==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.15.0.tgz", + "integrity": "sha512-gjyB/rHAopL/XxfmYThQbXbzRMGhZzGw6KpcMbfe8Q3nNQKStpxnUKeXb0KiN/fFDR42Z43szs6rY7eHk0zdGQ==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "7.14.1", - "@typescript-eslint/visitor-keys": "7.14.1", + "@typescript-eslint/types": "7.15.0", + "@typescript-eslint/visitor-keys": "7.15.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -2150,16 +2150,16 @@ "license": "MIT" }, "node_modules/@typescript-eslint/utils": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.14.1.tgz", - "integrity": "sha512-CMmVVELns3nak3cpJhZosDkm63n+DwBlDX8g0k4QUa9BMnF+lH2lr3d130M1Zt1xxmB3LLk3NV7KQCq86ZBBhQ==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.15.0.tgz", + "integrity": "sha512-hfDMDqaqOqsUVGiEPSMLR/AjTSCsmJwjpKkYQRo1FNbmW4tBwBspYDwO9eh7sKSTwMQgBw9/T4DHudPaqshRWA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.14.1", - "@typescript-eslint/types": "7.14.1", - "@typescript-eslint/typescript-estree": "7.14.1" + "@typescript-eslint/scope-manager": "7.15.0", + "@typescript-eslint/types": "7.15.0", + "@typescript-eslint/typescript-estree": "7.15.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -2173,13 +2173,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.14.1.tgz", - "integrity": "sha512-Crb+F75U1JAEtBeQGxSKwI60hZmmzaqA3z9sYsVm8X7W5cwLEm5bRe0/uXS6+MR/y8CVpKSR/ontIAIEPFcEkA==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.15.0.tgz", + "integrity": "sha512-Hqgy/ETgpt2L5xueA/zHHIl4fJI2O4XUE9l4+OIfbJIRSnTJb/QscncdqqZzofQegIJugRIF57OJea1khw2SDw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.14.1", + "@typescript-eslint/types": "7.15.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -6583,9 +6583,9 @@ } }, "node_modules/typescript": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", - "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", "dev": true, "license": "Apache-2.0", "bin": { @@ -6597,15 +6597,15 @@ } }, "node_modules/typescript-eslint": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.14.1.tgz", - "integrity": "sha512-Eo1X+Y0JgGPspcANKjeR6nIqXl4VL5ldXLc15k4m9upq+eY5fhU2IueiEZL6jmHrKH8aCfbIvM/v3IrX5Hg99w==", + "version": "7.15.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.15.0.tgz", + "integrity": "sha512-Ta40FhMXBCwHura4X4fncaCVkVcnJ9jnOq5+Lp4lN8F4DzHZtOwZdRvVBiNUGznUDHPwdGnrnwxmUOU2fFQqFA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "7.14.1", - "@typescript-eslint/parser": "7.14.1", - "@typescript-eslint/utils": "7.14.1" + "@typescript-eslint/eslint-plugin": "7.15.0", + "@typescript-eslint/parser": "7.15.0", + "@typescript-eslint/utils": "7.15.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" diff --git a/package.json b/package.json index 98a22a9d..6fafd5f2 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "deepCleanRebuild": "npm run deepClean && npm install && npm run build && npm ls rimraf inflight glob", "prepublishOnly": "npm run wtf:uninstall && npm uninstall matter-history && npm install matter-history && npm run lint && npm run cleanBuild", "checkDependencies": "npx npm-check-updates", - "updateDepend encies": "npx npm-check-updates -u && npm install & npm run cleanBuild", + "updateDependencies": "npx npm-check-updates -u && npm install & npm run cleanBuild", "updateMatter:latest": "npm run deepClean && npm install @project-chip/matter-node.js@latest && npm install && npm run build", "updateMatter:dev": "npm run deepClean && npm install @project-chip/matter-node.js@dev && npm install && npm run build", "wtf:install": "npm install wtfnode && npm install --save-dev @types/wtfnode", @@ -132,7 +132,7 @@ "prettier": "^3.3.2", "rimraf": "^5.0.7", "ts-jest": "^29.1.5", - "typescript": "^5.5.2", - "typescript-eslint": "^7.14.1" + "typescript": "^5.5.3", + "typescript-eslint": "^7.15.0" } } \ No newline at end of file diff --git a/src/matterbridgeDeviceV8.ts b/src/matterbridgeDeviceV8.ts index e244dc25..d515a05e 100644 --- a/src/matterbridgeDeviceV8.ts +++ b/src/matterbridgeDeviceV8.ts @@ -84,7 +84,7 @@ import { AtLeastOne, MakeMandatory, NamedHandler } from '@project-chip/matter-no import { ClusterId, EndpointNumber, VendorId } from '@project-chip/matter-node.js/datatype'; // Matterbridge imports -import { AnsiLogger, CYAN, TimestampFormat, db, hk, rs, zb } from 'node-ansi-logger'; +import { AnsiLogger, CYAN, TimestampFormat, db, debugStringify, hk, rs, zb } from 'node-ansi-logger'; import { BooleanStateConfiguration, BooleanStateConfigurationCluster } from './cluster/BooleanStateConfigurationCluster.js'; import { PowerTopology, PowerTopologyCluster } from './cluster/PowerTopologyCluster.js'; import { ElectricalPowerMeasurement, ElectricalPowerMeasurementCluster } from './cluster/ElectricalPowerMeasurementCluster.js'; @@ -254,26 +254,17 @@ export class MatterbridgeDeviceV8 extends Endpoint { */ addDeviceType(deviceType: DeviceTypeDefinition) { if (!this.deviceTypes.has(deviceType.code)) { + // Keep the Matterbridge internal map this.log.debug(`addDeviceType: ${zb}${deviceType.code}${db}-${zb}${deviceType.name}${db}`); - /* - this.lifecycle.ready.on(() => { - this.act((agent) => - agent.get(DescriptorServer).addDeviceTypes({ - deviceType: deviceType.code, - revision: deviceType.revision, - }), - ); - }); - */ - /* - this.act((agent) => - agent.get(DescriptorServer).addDeviceTypes({ - deviceType: deviceType.code, - revision: deviceType.revision, - }), - ); - */ this.deviceTypes.set(deviceType.code, deviceType); + // Add the device types to the descriptor server + const deviceTypeList = Array.from(this.deviceTypes.values()).map((dt) => ({ + deviceType: dt.code, + revision: dt.revision, + })); + this.behaviors.require(DescriptorServer, { + deviceTypeList, + }); } } @@ -286,7 +277,6 @@ export class MatterbridgeDeviceV8 extends Endpoint { addDeviceTypeWithClusterServer(deviceTypes: AtLeastOne, includeServerList: ClusterId[]) { this.log.debug('addDeviceTypeWithClusterServer:'); deviceTypes.forEach((deviceType) => { - this.addDeviceType(deviceType); this.log.debug(`- with deviceType: ${zb}${deviceType.code}${db}-${zb}${deviceType.name}${db}`); deviceType.requiredServerClusters.forEach((clusterId) => { if (!includeServerList.includes(clusterId)) includeServerList.push(clusterId); @@ -295,6 +285,9 @@ export class MatterbridgeDeviceV8 extends Endpoint { includeServerList.forEach((clusterId) => { this.log.debug(`- with cluster: ${hk}${clusterId}${db}-${hk}${getClusterNameById(clusterId)}${db}`); }); + deviceTypes.forEach((deviceType) => { + this.addDeviceType(deviceType); + }); this.addClusterServerFromList(this, includeServerList); } @@ -343,12 +336,12 @@ export class MatterbridgeDeviceV8 extends Endpoint { const options: Record = {}; for (const attribute of Object.values(cluster.attributes)) { if ((attribute as AttributeServer).id < 0xfff0) { - // No issue here for value, as cluster is just a definition without getter setter + // No issue here for value, as cluster here is just a definition without getter setter // eslint-disable-next-line @typescript-eslint/no-explicit-any options[(attribute as AttributeServer).name] = (attribute as any).value; } } - this.log.debug(`addClusterServer: ${cluster.name} with options:${rs}\n`, options); + this.log.debug(`addClusterServer: ${hk}${cluster.id}${db}-${hk}${getClusterNameById(cluster.id)}${db} with options: ${debugStringify(options)}${rs}`); const behavior = MatterbridgeDeviceV8.getBehaviourTypeFromClusterServerId(cluster.id); this.behaviors.require(behavior, options); this.clusterServers.set(cluster.id, cluster); diff --git a/src/matterbridgeV8.ts b/src/matterbridgeV8.ts index 3e5a86b1..5497c899 100644 --- a/src/matterbridgeV8.ts +++ b/src/matterbridgeV8.ts @@ -437,7 +437,7 @@ export class MatterbridgeV8 extends EventEmitter { } */ - log.notice(`Creating lightEndpoint1 to ${await storageContext.get('storeId')} aggregator`); + log.notice(`Creating lightEndpoint1 -> OnOffLightDevice.with(BridgedDeviceBasicInformationServer)`); const lightEndpoint1 = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), { id: 'OnOffLight', bridgedDeviceBasicInformation: { @@ -452,7 +452,16 @@ export class MatterbridgeV8 extends EventEmitter { uniqueId: '0x123456789', reachable: true, }, + /* + descriptor: { + deviceTypeList: [ + { deviceType: 0x100, revision: 3 }, + { deviceType: 0x0302, revision: 2 }, + ], + }, + */ }); + /* await lightEndpoint1.act(async (agent) => (await agent.load(DescriptorServer)).addDeviceTypes({ deviceType: DeviceTypeId(0x0302), @@ -460,7 +469,6 @@ export class MatterbridgeV8 extends EventEmitter { }), ); log.notice(`Added device type to lightEndpoint1`); - /* lightEndpoint1.lifecycle.ready.on(() => { log.notice('Light is ready'); lightEndpoint1.act((agent) => @@ -481,12 +489,11 @@ export class MatterbridgeV8 extends EventEmitter { ); */ - // logEndpoint(EndpointServer.forEndpoint(lightEndpoint1)); - log.notice(`Adding lightEndpoint1 to ${await storageContext.get('storeId')} aggregator`); await this.matterAggregator.add(lightEndpoint1); + // logEndpoint(EndpointServer.forEndpoint(lightEndpoint1)); - log.notice(`Adding switchEnpoint2 to ${await storageContext.get('storeId')} aggregator`); + log.notice(`Creating switchEnpoint2`); const switchEnpoint2 = new Endpoint(GenericSwitchDevice.with(BridgedDeviceBasicInformationServer, SwitchServer.with('MomentarySwitch', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress', 'MomentarySwitchRelease')), { id: 'GenericSwitch', bridgedDeviceBasicInformation: { @@ -508,15 +515,19 @@ export class MatterbridgeV8 extends EventEmitter { }, }); + log.notice(`Adding switchEnpoint2 to ${await storageContext.get('storeId')} aggregator`); await this.matterAggregator.add(switchEnpoint2); + // logEndpoint(EndpointServer.forEndpoint(switchEnpoint2)); + switchEnpoint2.events.identify.startIdentifying.on(() => log.notice('GenericSwitch.identify logic, ideally blink a light every 0.5s ...')); switchEnpoint2.events.switch.currentPosition$Changed.on(() => log.notice('GenericSwitch.currentPosition changed ...')); // switchEnpoint2.act((agent) => agent.switch.events.initialPress.emit({ newPosition: 1 }, agent.context)); // switchEnpoint2.events.switch.emit('initialPress', { newPosition: 1 }, switchEnpoint2.events.switch.context); - log.notice(`Adding matterbridge device to ${await storageContext.get('storeId')} aggregator`); - const matterbridgeDevice3 = new MatterbridgeDeviceV8(DeviceTypes.TEMPERATURE_SENSOR, { uniqueStorageKey: 'TemperatureSensor' }); - matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.HUMIDITY_SENSOR], [TemperatureMeasurement.Cluster.id, RelativeHumidityMeasurement.Cluster.id]); + log.notice(`Creating matterbridge device ClimateSensor`); + const matterbridgeDevice3 = new MatterbridgeDeviceV8(DeviceTypes.TEMPERATURE_SENSOR, { uniqueStorageKey: 'ClimateSensor' }); + matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.TEMPERATURE_SENSOR], [TemperatureMeasurement.Cluster.id]); + matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.HUMIDITY_SENSOR], [RelativeHumidityMeasurement.Cluster.id]); matterbridgeDevice3.addDeviceTypeWithClusterServer([DeviceTypes.PRESSURE_SENSOR], [PressureMeasurement.Cluster.id]); /* matterbridgeDevice3.behaviors.require(IdentifyServer, { @@ -528,19 +539,35 @@ export class MatterbridgeV8 extends EventEmitter { maxMeasuredValue: null, }); */ + + log.notice(`Adding BridgedDeviceBasicInformationServer to ClimateSensor`); matterbridgeDevice3.behaviors.require(BridgedDeviceBasicInformationServer, { vendorId: VendorId(await storageContext.get('vendorId')), vendorName: await storageContext.get('vendorName'), - productName: 'TemperatureSensor', - productLabel: 'TemperatureSensor', - nodeLabel: 'TemperatureSensor', + productName: 'ClimateSensor', + productLabel: 'ClimateSensor', + nodeLabel: 'ClimateSensor', serialNumber: '0x145456739', uniqueId: '0x124556739', reachable: true, }); + + log.notice(`Adding DescriptorServer to ClimateSensor`); + /* + matterbridgeDevice3.behaviors.require(DescriptorServer, { + deviceTypeList: [ + { deviceType: 0x0302, revision: 2 }, + { deviceType: 0x0307, revision: 2 }, + { deviceType: 0x0305, revision: 2 }, + ], + }); + */ + + log.notice(`Adding ClimateSensor to ${await storageContext.get('storeId')} aggregator`); await this.matterAggregator.add(matterbridgeDevice3); + logEndpoint(EndpointServer.forEndpoint(matterbridgeDevice3)); await this.startServerNode(storageContext);