Skip to content

Commit

Permalink
Remove Thread credential sync from start of Matter commissioning flow (
Browse files Browse the repository at this point in the history
…#4150)

- After discussion with Thread dev, remove Thread credential syncing from the start of the Matter commissioning flow. There are 2 major reasons for this:
   * it significantly slows down the flow while only being useful some of the time
   * the results have limited usefulness because the API limits how much Home Assistant can influence the device data
  The alternative for the user is to use the manual 'import credentials' button in the frontend (matching iOS), or access the sync option in the app settings > troubleshooting menu.
  • Loading branch information
jpelgrom authored Jan 24, 2024
1 parent ff2b0ec commit d9e65f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.homeassistant.companion.android.matter

import android.app.Application
import android.content.IntentSender
import android.util.Log
import androidx.activity.result.ActivityResult
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -91,24 +90,12 @@ class MatterCommissioningViewModel @Inject constructor(
}
}

suspend fun syncThreadIfNecessary(): IntentSender? {
fun syncThreadIfNecessary(): IntentSender? {
step = CommissioningFlowStep.Working
return try {
val result = threadManager.syncPreferredDataset(
getApplication<Application>().applicationContext,
serverId,
false,
viewModelScope
)
when (result) {
is ThreadManager.SyncResult.OnlyOnDevice -> result.exportIntent
is ThreadManager.SyncResult.AllHaveCredentials -> result.exportIntent
else -> null
}
} catch (e: Exception) {
Log.w(TAG, "Unable to sync preferred Thread dataset, continuing", e)
null
}
// The app used to sync Thread credentials here until commit 26a472a, but it was
// (temporarily?) removed due to slowing down the Matter commissioning flow for the user
// and limited usefulness of the result (because of API limitations)
return null
}

fun onThreadPermissionResult(result: ActivityResult, code: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,11 @@ class WebViewPresenterImpl @Inject constructor(
if (_matterThreadStep.value != MatterThreadStep.REQUESTED) {
_matterThreadStep.tryEmit(MatterThreadStep.REQUESTED)

mainScope.launch {
val deviceThreadIntent = try {
when (val result = threadUseCase.syncPreferredDataset(context, serverId, false, CoroutineScope(coroutineContext + SupervisorJob()))) {
is ThreadManager.SyncResult.OnlyOnDevice -> result.exportIntent
is ThreadManager.SyncResult.AllHaveCredentials -> result.exportIntent
else -> null
}
} catch (e: Exception) {
Log.w(TAG, "Unable to sync preferred Thread dataset, continuing", e)
null
}
if (deviceThreadIntent != null) {
matterThreadIntentSender = deviceThreadIntent
_matterThreadStep.tryEmit(MatterThreadStep.THREAD_EXPORT_TO_SERVER_MATTER)
} else {
startMatterCommissioningFlow(context)
}
}
// The app used to sync Thread credentials here until commit 26a472a, but it was
// (temporarily?) removed due to slowing down the Matter commissioning flow for the user
// and limited usefulness of the result (because of API limitations)

startMatterCommissioningFlow(context)
} // else already waiting for a result, don't send another request
}

Expand Down

0 comments on commit d9e65f8

Please sign in to comment.