From ca0703a9a3dfc04455c525f65fa03af3732b037d Mon Sep 17 00:00:00 2001 From: KremeCN <3265494849@qq.com> Date: Sat, 22 Aug 2026 22:21:34 +0800 Subject: [PATCH] fix: make infrared downloads provider scoped --- .../com/flagship/abox/manager/domain/Models.kt | 1 - .../manager/testing/fakes/FakeDeviceGateways.kt | 13 ++++++++----- .../manager/testing/fakes/FakeDeviceGatewaysTest.kt | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/domain/src/main/kotlin/com/flagship/abox/manager/domain/Models.kt b/domain/src/main/kotlin/com/flagship/abox/manager/domain/Models.kt index bbf62e1..5b282fe 100644 --- a/domain/src/main/kotlin/com/flagship/abox/manager/domain/Models.kt +++ b/domain/src/main/kotlin/com/flagship/abox/manager/domain/Models.kt @@ -76,7 +76,6 @@ data class TemperatureHumidityReading( ) data class InfraredCode( - val profileId: ProviderProfileId, val deviceName: DeviceName, val key: String, val code: String, diff --git a/testing/fakes/src/main/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGateways.kt b/testing/fakes/src/main/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGateways.kt index ae2622a..cbd527b 100644 --- a/testing/fakes/src/main/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGateways.kt +++ b/testing/fakes/src/main/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGateways.kt @@ -80,7 +80,8 @@ class FakeTemperatureHumidityGateway : TemperatureHumidityGateway { class FakeInfraredGateway : InfraredGateway { val sentKeys: MutableList = Collections.synchronizedList(mutableListOf()) val learnedKeys: MutableList = Collections.synchronizedList(mutableListOf()) - val downloadedCodes: MutableList = Collections.synchronizedList(mutableListOf()) + val downloadCalls: MutableList = + Collections.synchronizedList(mutableListOf()) @Volatile var sendResult: DomainResult = DomainResult.Success(Unit) @@ -113,11 +114,8 @@ class FakeInfraredGateway : InfraredGateway { profileId: ProviderProfileId, codes: List, ): DomainResult> { - require(codes.all { it.profileId == profileId }) { - "All infrared codes must belong to the supplied provider profile" - } downloadError?.let { return DomainResult.Failure(it) } - downloadedCodes += codes + downloadCalls += InfraredDownloadCall(profileId, codes) return DomainResult.Success(codes.map { InfraredCodeDownloadResult(it, successful = true) }) } } @@ -128,6 +126,11 @@ data class InfraredCall( val key: String, ) +data class InfraredDownloadCall( + val profileId: ProviderProfileId, + val codes: List, +) + private data class DeviceKey( val profileId: ProviderProfileId, val deviceName: DeviceName, diff --git a/testing/fakes/src/test/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGatewaysTest.kt b/testing/fakes/src/test/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGatewaysTest.kt index 70ff75d..8b46b3a 100644 --- a/testing/fakes/src/test/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGatewaysTest.kt +++ b/testing/fakes/src/test/kotlin/com/flagship/abox/manager/testing/fakes/FakeDeviceGatewaysTest.kt @@ -43,7 +43,7 @@ class FakeDeviceGatewaysTest { fun infraredGatewayRecordsCallsAndResults() = runTest { val gateway = FakeInfraredGateway() val deviceName = DeviceName("ir-1") - val code = InfraredCode(profileOne, deviceName, "power", "code-value") + val code = InfraredCode(deviceName, "power", "code-value") gateway.sendKey(profileOne, deviceName, "power") gateway.learnKey(profileOne, deviceName, "volume-up") @@ -51,7 +51,7 @@ class FakeDeviceGatewaysTest { assertEquals(InfraredCall(profileOne, deviceName, "power"), gateway.sentKeys.single()) assertEquals("volume-up", gateway.learnedKeys.single().key) - assertEquals(listOf(code), gateway.downloadedCodes) + assertEquals(InfraredDownloadCall(profileOne, listOf(code)), gateway.downloadCalls.single()) assertTrue(download is DomainResult.Success) } }