combov2: Avoid duplicate CONNECTED pump status events

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-26 23:06:42 +01:00
parent b2375d54c7
commit 797b3d9674

View file

@ -1925,12 +1925,18 @@ class ComboV2Plugin @Inject constructor (
aapsLogger.info(LTag.PUMP, "Setting Combo driver state: old: $oldState new: $newState") aapsLogger.info(LTag.PUMP, "Setting Combo driver state: old: $oldState new: $newState")
// TODO: Is it OK to send CONNECTED twice? It can happen when changing from Ready to Suspended.
when (newState) { when (newState) {
DriverState.Disconnected -> rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)) DriverState.Disconnected -> rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED))
DriverState.Connecting -> rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING)) DriverState.Connecting -> rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING))
DriverState.Ready, // Filter Ready<->Suspended state changes to avoid sending CONNECTED unnecessarily often.
DriverState.Suspended -> rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)) DriverState.Ready -> {
if (oldState != DriverState.Suspended)
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED))
}
DriverState.Suspended -> {
if (oldState != DriverState.Ready)
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED))
}
else -> Unit else -> Unit
} }
} }