[EOPATCH2]
1. Create zero temp basal of type TemporaryBasal.Type.PUMP_SUSPEND on suspend
This commit is contained in:
parent
b952be1a36
commit
6fc3825503
|
@ -2,12 +2,15 @@ package info.nightscout.androidaps.plugins.pump.eopatch.alarm
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.EONotification
|
import info.nightscout.androidaps.plugins.pump.eopatch.EONotification
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus
|
import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.R
|
import info.nightscout.androidaps.plugins.pump.eopatch.R
|
||||||
|
@ -18,6 +21,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.code.AlarmCategory
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm
|
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.ui.AlarmHelperActivity
|
import info.nightscout.androidaps.plugins.pump.eopatch.ui.AlarmHelperActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
|
import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import info.nightscout.shared.logging.AAPSLogger
|
import info.nightscout.shared.logging.AAPSLogger
|
||||||
|
@ -55,6 +59,9 @@ class AlarmManager @Inject constructor() : IAlarmManager {
|
||||||
@Inject lateinit var pm: IPreferenceManager
|
@Inject lateinit var pm: IPreferenceManager
|
||||||
@Inject lateinit var mAlarmRegistry: IAlarmRegistry
|
@Inject lateinit var mAlarmRegistry: IAlarmRegistry
|
||||||
|
|
||||||
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
@Inject lateinit var pumpSync: PumpSync
|
||||||
|
|
||||||
private lateinit var mAlarmProcess: AlarmProcess
|
private lateinit var mAlarmProcess: AlarmProcess
|
||||||
|
|
||||||
private var compositeDisposable: CompositeDisposable = CompositeDisposable()
|
private var compositeDisposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
@ -157,6 +164,14 @@ class AlarmManager @Inject constructor() : IAlarmManager {
|
||||||
}
|
}
|
||||||
.subscribe { ret ->
|
.subscribe { ret ->
|
||||||
if(ret == IAlarmProcess.ALARM_HANDLED){
|
if(ret == IAlarmProcess.ALARM_HANDLED){
|
||||||
|
if(alarmCode == B001){
|
||||||
|
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||||
|
timestamp = dateUtil.now(),
|
||||||
|
endPumpId = dateUtil.now(),
|
||||||
|
pumpType = PumpType.EOFLOW_EOPATCH2,
|
||||||
|
pumpSerial = patchManager.patchConfig.patchSerialNumber
|
||||||
|
)
|
||||||
|
}
|
||||||
updateState(alarmCode, AlarmState.HANDLE)
|
updateState(alarmCode, AlarmState.HANDLE)
|
||||||
}else{
|
}else{
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
|
|
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.Transformations
|
import androidx.lifecycle.Transformations
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.R
|
import info.nightscout.androidaps.plugins.pump.eopatch.R
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPatchManager
|
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPatchManager
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager
|
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager
|
||||||
|
@ -16,7 +17,12 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig
|
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig
|
||||||
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState
|
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
import info.nightscout.shared.logging.AAPSLogger
|
||||||
|
import info.nightscout.shared.logging.LTag
|
||||||
import io.reactivex.rxjava3.core.Observable
|
import io.reactivex.rxjava3.core.Observable
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -30,7 +36,10 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
val patchManager: IPatchManager,
|
val patchManager: IPatchManager,
|
||||||
private val preferenceManager: IPreferenceManager,
|
private val preferenceManager: IPreferenceManager,
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
private val aapsSchedulers: AapsSchedulers
|
private val aapsSchedulers: AapsSchedulers,
|
||||||
|
private val aapsLogger: AAPSLogger,
|
||||||
|
private val dateUtil: DateUtil,
|
||||||
|
private val pumpSync: PumpSync
|
||||||
) : EoBaseViewModel<EoBaseNavigator>() {
|
) : EoBaseViewModel<EoBaseNavigator>() {
|
||||||
private val _eventHandler = SingleLiveEvent<UIEvent<EventType>>()
|
private val _eventHandler = SingleLiveEvent<UIEvent<EventType>>()
|
||||||
val eventHandler : LiveData<UIEvent<EventType>>
|
val eventHandler : LiveData<UIEvent<EventType>>
|
||||||
|
@ -208,6 +217,18 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe({ response ->
|
.subscribe({ response ->
|
||||||
if (response.isSuccess) {
|
if (response.isSuccess) {
|
||||||
|
var result = pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
|
timestamp = dateUtil.now(),
|
||||||
|
rate = 0.0,
|
||||||
|
duration = T.mins((pauseDurationHour * 60).toLong()).msecs(),
|
||||||
|
isAbsolute = true,
|
||||||
|
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
||||||
|
pumpId = dateUtil.now(),
|
||||||
|
pumpType = PumpType.EOFLOW_EOPATCH2,
|
||||||
|
pumpSerial = patchManager.patchConfig.patchSerialNumber
|
||||||
|
)
|
||||||
|
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId: Result: $result")
|
||||||
|
|
||||||
UIEvent(EventType.PAUSE_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
|
UIEvent(EventType.PAUSE_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
|
||||||
startPauseTimeUpdate()
|
startPauseTimeUpdate()
|
||||||
} else {
|
} else {
|
||||||
|
@ -224,6 +245,12 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isSuccess) {
|
if (it.isSuccess) {
|
||||||
|
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||||
|
timestamp = dateUtil.now(),
|
||||||
|
endPumpId = dateUtil.now(),
|
||||||
|
pumpType = PumpType.EOFLOW_EOPATCH2,
|
||||||
|
pumpSerial = patchManager.patchConfig.patchSerialNumber
|
||||||
|
)
|
||||||
UIEvent(EventType.RESUME_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
|
UIEvent(EventType.RESUME_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
|
||||||
stopPauseTimeUpdate()
|
stopPauseTimeUpdate()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue