From be3a67f52577c51911eb7a76e8ccefcaf4bdfa1d Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Sat, 11 Nov 2023 22:16:08 +0100 Subject: [PATCH] Working on controller --- src-admin/src/components/ConfigHandler.js | 5 ++ src/matter/BridgedDevicesNode.ts | 2 +- src/matter/ControllerNode.ts | 88 +++++++++++++++++++++-- src/matter/DeviceNode.ts | 2 +- 4 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src-admin/src/components/ConfigHandler.js b/src-admin/src/components/ConfigHandler.js index 773148d3..3f762635 100644 --- a/src-admin/src/components/ConfigHandler.js +++ b/src-admin/src/components/ConfigHandler.js @@ -1,4 +1,5 @@ import PropTypes from 'prop-types'; +import { v4 as uuidv4 } from 'uuid'; class ConfigHandler { constructor(instance, socket, onChanged, onCommissioningChanged) { @@ -190,8 +191,12 @@ class ConfigHandler { native: { enabled: false, ble: false, + uuid: uuidv4(), }, }); + } else if (!controllerObj.native.uuid) { + controllerObj.native.uuid = uuidv4(); + await this.socket.setObject(controllerObj._id, controllerObj); } controllerObj = controllerObj || {}; diff --git a/src/matter/BridgedDevicesNode.ts b/src/matter/BridgedDevicesNode.ts index 6a2d3134..fffdc9e1 100644 --- a/src/matter/BridgedDevicesNode.ts +++ b/src/matter/BridgedDevicesNode.ts @@ -175,7 +175,7 @@ class BridgedDevices { this.commissioningServer.addDevice(aggregator); try { - this.matterServer?.addCommissioningServer(this.commissioningServer, {uniqueNodeId: this.parameters.uuid}); + this.matterServer?.addCommissioningServer(this.commissioningServer, { uniqueStorageKey: this.parameters.uuid }); } catch (e) { this.adapter.log.error(`Could not add commissioning server for device ${this.parameters.uuid}: ${e.message}`); } diff --git a/src/matter/ControllerNode.ts b/src/matter/ControllerNode.ts index 5c2e45a2..0d53c9ec 100644 --- a/src/matter/ControllerNode.ts +++ b/src/matter/ControllerNode.ts @@ -5,10 +5,16 @@ import { NodeCommissioningOptions, } from '@project-chip/matter-node.js'; import { NodeId } from '@project-chip/matter-node.js/datatype'; -import { Endpoint, PairedNode } from '@project-chip/matter-node.js/device'; +import { Endpoint } from '@project-chip/matter-node.js/device'; import { toHexString } from '@project-chip/matter-node.js/util'; -import { asClusterServerInternal, ClusterServerObj, GlobalAttributes } from '@project-chip/matter-node.js/cluster'; -import { AnyAttributeServer, FabricScopeError } from '@project-chip/matter-node.js/cluster'; +import { + asClusterServerInternal, + ClusterServerObj, + GlobalAttributes, + AnyAttributeServer, FabricScopeError, + +} from '@project-chip/matter-node.js/cluster'; +// import { EventClient } from '@project-chip/matter-node.js/cluster'; import { CommissionableDevice } from '@project-chip/matter-node.js/common'; import { ManualPairingCodeCodec, QrPairingCodeCodec } from '@project-chip/matter-node.js/schema'; @@ -30,6 +36,7 @@ export interface ControllerCreateOptions { export interface ControllerOptions { ble?: boolean; + uuid: string; } interface AddDeviceResult { @@ -67,8 +74,9 @@ class Controller { this.commissioningController = new CommissioningController({ autoConnect: false, }); + const uniqueStorageKey = this.parameters.uuid.replace(/-/g, '').split('.').pop() || '0000000000000000'; - this.matterServer?.addCommissioningController(this.commissioningController); + this.matterServer?.addCommissioningController(this.commissioningController, { uniqueStorageKey }); } async start(): Promise { @@ -204,15 +212,81 @@ class Controller { } } + logClusterClient(endpoint: Endpoint, clusterClient: any) { + const { supportedFeatures: features } = clusterClient; + const globalAttributes = GlobalAttributes(features); + const supportedFeatures = []; + for (const featureName in features) { + if (features[featureName] === true) { + supportedFeatures.push(featureName); + } + } + this.adapter.log.debug( + `Cluster-Client "${clusterClient.name}" (${toHexString(clusterClient.id)}) ${supportedFeatures.length ? `(Features: ${supportedFeatures.join(", ")})` : ""}` + ); + this.adapter.log.debug("Global-Attributes:"); + for (const attributeName in globalAttributes) { + const attribute = clusterClient.attributes[attributeName]; + if (attribute === void 0) { + continue; + } + this.adapter.log.debug(`"${attribute.name}" (${toHexString(attribute.id)})`); + } + + this.adapter.log.debug("Attributes:"); + for (const attributeName in clusterClient.attributes) { + if (attributeName in globalAttributes) { + continue; + } + const attribute = clusterClient.attributes[attributeName]; + if (attribute === void 0) { + continue; + } + // const present = attribute instanceof PresentAttributeClient; + // const unknown = attribute instanceof UnknownPresentAttributeClient; + // let info = ""; + // if (!present) { + // info += " (Not Present)"; + // } + // if (unknown) { + // info += " (Unknown)"; + // } + // this.adapter.log.debug(`"${attribute.name}" (${toHexString(attribute.id)})${info}`); + } + + this.adapter.log.debug("Commands:"); + for (const commandName in clusterClient.commands) { + this.adapter.log.debug(`"${commandName}"`); + } + + this.adapter.log.debug('Events:'); + for (const eventName in clusterClient.events) { + const event = clusterClient.events[eventName]; + if (event === void 0) { + continue; + } + // const present = event instanceof PresentEventClient; + // const unknown = event instanceof UnknownPresentEventClient; + // let info = ''; + // if (!present) { + // info += ' (Not Present)'; + // } + // if (unknown) { + // info += ' (Unknown)'; + // } + // this.adapter.log.debug(`"${event.name}" (${toHexString(event.id)})${info}`); + } + } + endPointToIoBrokerStructure(endpoint: Endpoint): void { this.adapter.log.info(`Endpoint ${endpoint.id} (${endpoint.name}):`); for (const clusterServer of endpoint.getAllClusterServers()) { this.logClusterServer(clusterServer); } - // for (const clusterClient of endpoint.getAllClusterClients()) { - // this.logClusterClient(endpoint, clusterClient, options); - // } + for (const clusterClient of endpoint.getAllClusterClients()) { + this.logClusterClient(endpoint, clusterClient); + } for (const childEndpoint of endpoint.getChildEndpoints()) { this.endPointToIoBrokerStructure(childEndpoint); diff --git a/src/matter/DeviceNode.ts b/src/matter/DeviceNode.ts index 81df7b56..abe5a9e7 100644 --- a/src/matter/DeviceNode.ts +++ b/src/matter/DeviceNode.ts @@ -146,7 +146,7 @@ class Device { } try { - this.matterServer?.addCommissioningServer(this.commissioningServer, { uniqueNodeId: this.parameters.uuid }); + this.matterServer?.addCommissioningServer(this.commissioningServer, { uniqueStorageKey: this.parameters.uuid }); } catch (e) { this.adapter.log.error(`Could not add commissioning server for device ${this.parameters.uuid}: ${e.message}`); }