From 7d73ceb7b9626477d5834ca98e29ea0005fdf90b Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Wed, 13 Dec 2023 17:44:26 -0800 Subject: [PATCH] Remove pair step before calling any cluster API (#30968) * Remove pair step before calling any cluster API * Address review comments --- .../pairing/PairOnNetworkLongImInvokeCommand.kt | 14 +++----------- .../pairing/PairOnNetworkLongImReadCommand.kt | 14 +++----------- .../pairing/PairOnNetworkLongImWriteCommand.kt | 14 +++----------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt index 5e80ef13daddb5..1b66fa5886f7f4 100644 --- a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt +++ b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt @@ -37,21 +37,13 @@ class PairOnNetworkLongImInvokeCommand( DiscoveryFilterType.LONG_DISCRIMINATOR ) { override fun runCommand() { - currentCommissioner() - .pairDevice( - getNodeId(), - getRemoteAddr().address.hostAddress, - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - ) - currentCommissioner().setCompletionListener(this) - waitCompleteMs(getTimeoutMillis()) - runBlocking { try { val identifyTime: UShort = 1u val identifyCluster = IdentifyCluster(controller = currentCommissioner(), endpointId = 0u) + + // By running command identify, we are implicitly requesting CASE to be established if it's + // not already present. identifyCluster.identify(identifyTime) logger.log(Level.INFO, "Invoke command succeeded") } catch (ex: Exception) { diff --git a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt index ba4ae1ac938f2b..d1f2c37f318c35 100644 --- a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt +++ b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt @@ -17,22 +17,14 @@ class PairOnNetworkLongImReadCommand(controller: MatterController, credsIssue: C DiscoveryFilterType.LONG_DISCRIMINATOR ) { override fun runCommand() { - currentCommissioner() - .pairDevice( - getNodeId(), - getRemoteAddr().address.hostAddress, - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - ) - currentCommissioner().setCompletionListener(this) - waitCompleteMs(getTimeoutMillis()) - runBlocking { try { val basicInformationCluster = BasicInformationCluster(controller = currentCommissioner(), endpointId = DEFAULT_ENDPOINT) val vendorName = basicInformationCluster.readVendorNameAttribute() + + // By running command readVendorIDAttribute, we are implicitly requesting CASE to be + // established if it's not already present. val vendorId = basicInformationCluster.readVendorIDAttribute() logger.log(Level.INFO, "Read command succeeded, Verdor Name:${vendorName} (ID:${vendorId})") } catch (ex: Exception) { diff --git a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt index f87d827a0bc32a..161c8d3133f26f 100644 --- a/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt +++ b/examples/kotlin-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt @@ -37,21 +37,13 @@ class PairOnNetworkLongImWriteCommand( DiscoveryFilterType.LONG_DISCRIMINATOR ) { override fun runCommand() { - currentCommissioner() - .pairDevice( - getNodeId(), - getRemoteAddr().address.hostAddress, - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - ) - currentCommissioner().setCompletionListener(this) - waitCompleteMs(getTimeoutMillis()) - runBlocking { try { val basicInformationCluster = BasicInformationCluster(controller = currentCommissioner(), endpointId = DEFAULT_ENDPOINT) + + // By running command writeNodeLabelAttribute, we are implicitly requesting CASE to be + // established if it's not already present. basicInformationCluster.writeNodeLabelAttribute("Test Node Label") logger.log(Level.INFO, "Write command succeeded")