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)