fix: make infrared downloads provider scoped

This commit is contained in:
KremeCN
2026-08-22 22:21:34 +08:00
parent cbc2dc7ec5
commit ca0703a9a3
3 changed files with 10 additions and 8 deletions
@@ -80,7 +80,8 @@ class FakeTemperatureHumidityGateway : TemperatureHumidityGateway {
class FakeInfraredGateway : InfraredGateway {
val sentKeys: MutableList<InfraredCall> = Collections.synchronizedList(mutableListOf())
val learnedKeys: MutableList<InfraredCall> = Collections.synchronizedList(mutableListOf())
val downloadedCodes: MutableList<InfraredCode> = Collections.synchronizedList(mutableListOf())
val downloadCalls: MutableList<InfraredDownloadCall> =
Collections.synchronizedList(mutableListOf())
@Volatile
var sendResult: DomainResult<Unit> = DomainResult.Success(Unit)
@@ -113,11 +114,8 @@ class FakeInfraredGateway : InfraredGateway {
profileId: ProviderProfileId,
codes: List<InfraredCode>,
): DomainResult<List<InfraredCodeDownloadResult>> {
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<InfraredCode>,
)
private data class DeviceKey(
val profileId: ProviderProfileId,
val deviceName: DeviceName,
@@ -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)
}
}