feat: route infrared through selected device

This commit is contained in:
2026-08-26 19:55:30 +08:00
parent 4798ae32ba
commit 26ab5095e5
4 changed files with 44 additions and 13 deletions
@@ -49,6 +49,9 @@ class InfraredHubViewModel @Inject constructor(
val profileId: ProviderProfileId? = rawProfileId?.takeIf { it.isNotBlank() }?.let { ProviderProfileId(it) }
private val messageFlow = MutableStateFlow<HubUiMessage?>(null)
private val routeDeviceName: DeviceName? = savedStateHandle.get<String>("deviceName")
?.takeIf { it.isNotBlank() }
?.let(::DeviceName)
private data class HubSnapshot(
val providerProfile: ProviderProfile? = null,
@@ -68,7 +71,12 @@ class InfraredHubViewModel @Inject constructor(
when (devResult) {
is DomainResult.Failure -> flowOf(HubSnapshot(providerProfile = active, configError = devResult.error))
is DomainResult.Success -> {
val deviceName = devResult.value ?: DEFAULT_DEVICE_NAME
val deviceName = routeDeviceName ?: devResult.value ?: return@flatMapLatest flowOf(
HubSnapshot(
providerProfile = active,
configError = DomainError.InvalidRequest(detail = "No infrared device configured"),
),
)
combine(
virtualRemoteRepository.observeRemotes(profileId, deviceName),
virtualRemoteRepository.observeSlotQuota(profileId, deviceName),
@@ -40,6 +40,9 @@ class InfraredControlViewModel @Inject constructor(
private val deviceNameInputFlow = MutableStateFlow<String?>(null)
private val messageFlow = MutableStateFlow<InfraredUiMessage?>(null)
private val routeDeviceName: DeviceName? = savedStateHandle.get<String>("deviceName")
?.takeIf { it.isNotBlank() }
?.let(::DeviceName)
private data class ServerState(
val providerProfile: com.flagship.abox.manager.domain.ProviderProfile? = null,
@@ -65,7 +68,12 @@ class InfraredControlViewModel @Inject constructor(
),
)
is DomainResult.Success -> {
val deviceName = deviceResult.value ?: DEFAULT_DEVICE_NAME
val deviceName = routeDeviceName ?: deviceResult.value ?: return@flatMapLatest flowOf(
ServerState(
providerProfile = active,
configError = DomainError.InvalidRequest(detail = "No infrared device configured"),
),
)
combine(
virtualRemoteRepository.observeRemotes(profileId, deviceName),
virtualRemoteRepository.observeSlotQuota(profileId, deviceName),