fix: make infrared downloads provider scoped
This commit is contained in:
@@ -76,7 +76,6 @@ data class TemperatureHumidityReading(
|
||||
)
|
||||
|
||||
data class InfraredCode(
|
||||
val profileId: ProviderProfileId,
|
||||
val deviceName: DeviceName,
|
||||
val key: String,
|
||||
val code: String,
|
||||
|
||||
+8
-5
@@ -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,
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user