From 858f602518349bb8783e236c51fcb7d13bfef0d6 Mon Sep 17 00:00:00 2001 From: lauckhart Date: Mon, 11 Nov 2024 13:18:20 -0800 Subject: [PATCH] Fix commissioning on server restart (#1386) The commissioning window opened on restart but initiateCommissioning was not triggered except in the case of factory reset triggered by decommissioning. The resulted in the QR code not appearing. --- CHANGELOG.md | 1 + .../system/commissioning/CommissioningServer.ts | 2 +- .../system/network/ServerNetworkRuntime.ts | 16 ++++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f3810d84e..1530d60056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The main work (all changes without a GitHub username in brackets in the below li - @matter/node - Enhancement: The `with` functions on endpoint and cluster behavior types now alias to `withBehaviors` and `withFeatures` respectively to make their function more explicit + - Fix: Trigger CommissioningServer#initiateCommissioning when server restarts outside of factory reset - @matter/nodejs - Feature: New export @matter/nodejs/config allows for fine-grained configuration of Node.js bootstrap logic diff --git a/packages/node/src/behavior/system/commissioning/CommissioningServer.ts b/packages/node/src/behavior/system/commissioning/CommissioningServer.ts index 2fd71d60ac..38f4c3a098 100644 --- a/packages/node/src/behavior/system/commissioning/CommissioningServer.ts +++ b/packages/node/src/behavior/system/commissioning/CommissioningServer.ts @@ -151,7 +151,7 @@ export class CommissioningServer extends Behavior { } #triggerFactoryReset() { - this.env.runtime.add((this.endpoint as ServerNode).erase().then(this.callback(this.initiateCommissioning))); + this.env.runtime.add((this.endpoint as ServerNode).erase()); } #monitorFailsafe(failsafe: FailsafeContext) { diff --git a/packages/node/src/behavior/system/network/ServerNetworkRuntime.ts b/packages/node/src/behavior/system/network/ServerNetworkRuntime.ts index 6824c52ec9..07cc7ee2a6 100644 --- a/packages/node/src/behavior/system/network/ServerNetworkRuntime.ts +++ b/packages/node/src/behavior/system/network/ServerNetworkRuntime.ts @@ -275,16 +275,16 @@ export class ServerNetworkRuntime extends NetworkRuntime { // Monitor CommissioningServer to end "uncommissioned" mode when we are commissioned this.#observers.on(this.owner.eventsOf(CommissioningServer).commissioned, this.endUncommissionedMode); + // When first going online, enable commissioning by controllers unless we ourselves are configured as a + // controller + if (owner.state.commissioning.enabled === undefined) { + await owner.set({ + commissioning: { enabled: true }, + }); + } + // Ensure the environment will convey the commissioning configuration to the DeviceCommissioner if (!env.has(CommissioningConfigProvider)) { - // When first going online, enable commissioning by controllers unless we ourselves are configured as a - // controller - if (owner.state.commissioning.enabled === undefined) { - await owner.set({ - commissioning: { enabled: true }, - }); - } - // Configure the DeviceCommissioner env.set( CommissioningConfigProvider,