feat: confirm socket controls by readback
This commit is contained in:
+17
@@ -18,6 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList
|
||||
class FakeSocketGateway : SocketGateway {
|
||||
private val states = ConcurrentHashMap<DeviceKey, SocketPowerState>()
|
||||
private val errors = ConcurrentHashMap<DeviceKey, DomainError>()
|
||||
private val commandErrors = ConcurrentHashMap<DeviceKey, DomainError>()
|
||||
|
||||
override suspend fun getStatus(
|
||||
profileId: ProviderProfileId,
|
||||
@@ -35,11 +36,27 @@ class FakeSocketGateway : SocketGateway {
|
||||
return DomainResult.Success(SocketStatus(profileId, deviceName, powerState))
|
||||
}
|
||||
|
||||
override suspend fun commandPower(
|
||||
profileId: ProviderProfileId,
|
||||
deviceName: DeviceName,
|
||||
powerState: SocketPowerState,
|
||||
): DomainResult<Unit> {
|
||||
val key = DeviceKey(profileId, deviceName)
|
||||
commandErrors[key]?.let { return DomainResult.Failure(it) }
|
||||
states[key] = powerState
|
||||
return DomainResult.Success(Unit)
|
||||
}
|
||||
|
||||
fun setError(profileId: ProviderProfileId, deviceName: DeviceName, error: DomainError?) {
|
||||
val key = DeviceKey(profileId, deviceName)
|
||||
if (error == null) errors.remove(key) else errors[key] = error
|
||||
}
|
||||
|
||||
fun setCommandError(profileId: ProviderProfileId, deviceName: DeviceName, error: DomainError?) {
|
||||
val key = DeviceKey(profileId, deviceName)
|
||||
if (error == null) commandErrors.remove(key) else commandErrors[key] = error
|
||||
}
|
||||
|
||||
private fun resultFor(
|
||||
profileId: ProviderProfileId,
|
||||
deviceName: DeviceName,
|
||||
|
||||
Reference in New Issue
Block a user