From 5a9c3922b9c965cd38ea48c58a7ca84a91b6c2b4 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 2 Sep 2023 03:07:50 +0200 Subject: [PATCH] Fix Thread border agent IDs encoded as hex second instance (#3838) * Fix Thread border agent IDs encoded as hex second instance * Remove unnecessary toByteArray() and brackets * Fix indentation --- .../companion/android/thread/ThreadManagerImpl.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt index 84765259fdc..969d938c517 100644 --- a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt +++ b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt @@ -158,6 +158,7 @@ class ThreadManagerImpl @Inject constructor( override suspend fun getPreferredDatasetFromServer(serverId: Int): ThreadDatasetResponse? = getDatasetsFromServer(serverId)?.firstOrNull { it.preferred } + @OptIn(ExperimentalStdlibApi::class) override suspend fun importDatasetFromServer( context: Context, datasetId: String, @@ -166,13 +167,12 @@ class ThreadManagerImpl @Inject constructor( ) { val tlv = serverManager.webSocketRepository(serverId).getThreadDatasetTlv(datasetId)?.tlvAsByteArray if (tlv != null) { - val borderAgentId = ( - preferredBorderAgentId ?: run { - Log.w(TAG, "Adding dataset with placeholder border agent ID") - BORDER_AGENT_ID - } - ).toByteArray() - val threadBorderAgent = ThreadBorderAgent.newBuilder(borderAgentId).build() + val borderAgentId = preferredBorderAgentId ?: run { + Log.w(TAG, "Adding dataset with placeholder border agent ID") + BORDER_AGENT_ID + } + val idAsBytes = borderAgentId.let { if (it.length == 16) it.toByteArray() else it.hexToByteArray() } + val threadBorderAgent = ThreadBorderAgent.newBuilder(idAsBytes).build() val threadNetworkCredentials = ThreadNetworkCredentials.fromActiveOperationalDataset(tlv) suspendCoroutine { cont -> ThreadNetwork.getClient(context).addCredentials(threadBorderAgent, threadNetworkCredentials)