combov2: Send EventInitializationChanged

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-27 16:32:32 +01:00
parent e9f75f4f9b
commit da49a0c9b6

View file

@ -46,6 +46,7 @@ import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.interfaces.utils.TimeChangeType import info.nightscout.interfaces.utils.TimeChangeType
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.events.EventDismissNotification
import info.nightscout.rx.events.EventInitializationChanged
import info.nightscout.rx.events.EventOverviewBolusProgress import info.nightscout.rx.events.EventOverviewBolusProgress
import info.nightscout.rx.events.EventOverviewBolusProgress.Treatment import info.nightscout.rx.events.EventOverviewBolusProgress.Treatment
import info.nightscout.rx.events.EventPumpStatusChanged import info.nightscout.rx.events.EventPumpStatusChanged
@ -138,6 +139,7 @@ class ComboV2Plugin @Inject constructor (
// These are initialized in onStart() and torn down in onStop(). // These are initialized in onStart() and torn down in onStop().
private var bluetoothInterface: AndroidBluetoothInterface? = null private var bluetoothInterface: AndroidBluetoothInterface? = null
private var pumpManager: ComboCtlPumpManager? = null private var pumpManager: ComboCtlPumpManager? = null
private var initializationChangedEventSent = false
// These are initialized in connect() and torn down in disconnect(). // These are initialized in connect() and torn down in disconnect().
private var pump: ComboCtlPump? = null private var pump: ComboCtlPump? = null
@ -259,6 +261,8 @@ class ComboV2Plugin @Inject constructor (
_pairedStateUIFlow.value = paired _pairedStateUIFlow.value = paired
setDriverState(DriverState.Disconnected) setDriverState(DriverState.Disconnected)
// NOTE: EventInitializationChanged is sent in getPumpStatus() .
} }
override fun onStop() { override fun onStop() {
@ -282,6 +286,9 @@ class ComboV2Plugin @Inject constructor (
setDriverState(DriverState.NotInitialized) setDriverState(DriverState.NotInitialized)
rxBus.send(EventInitializationChanged())
initializationChangedEventSent = false
super.onStop() super.onStop()
} }
@ -638,6 +645,13 @@ class ComboV2Plugin @Inject constructor (
executeCommand { executeCommand {
pump?.updateStatus() pump?.updateStatus()
} }
// We send this event here, and not in onStart(), to include
// the initial pump status update before emitting the event.
if (!initializationChangedEventSent) {
rxBus.send(EventInitializationChanged())
initializationChangedEventSent = true
}
} catch (e: CancellationException) { } catch (e: CancellationException) {
throw e throw e
} catch (_: Exception) { } catch (_: Exception) {