This commit is contained in:
Milos Kozak 2021-10-03 19:01:07 +02:00
commit 9d99913282
6 changed files with 29 additions and 14 deletions

View file

@ -145,7 +145,7 @@ abstract class Trigger(val injector: HasAndroidInjector) {
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON( TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(
data.toString() data.toString()
) )
else -> throw ClassNotFoundException(type) else -> TriggerConnector(injector)
} }
} }

View file

@ -7,12 +7,16 @@ import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
abstract class ActionViewModelBase( abstract class ActionViewModelBase(
protected val injector: HasAndroidInjector, protected val injector: HasAndroidInjector,
protected val logger: AAPSLogger protected val logger: AAPSLogger
) : ViewModelBase() { ) : ViewModelBase() {
protected val disposable = CompositeDisposable()
private val _isActionExecutingLiveData = MutableLiveData(false) private val _isActionExecutingLiveData = MutableLiveData(false)
val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData
@ -22,7 +26,7 @@ abstract class ActionViewModelBase(
fun executeAction() { fun executeAction() {
_isActionExecutingLiveData.postValue(true) _isActionExecutingLiveData.postValue(true)
val disposable = doExecuteAction().subscribeBy( disposable += doExecuteAction().subscribeBy(
onSuccess = { result -> onSuccess = { result ->
_isActionExecutingLiveData.postValue(false) _isActionExecutingLiveData.postValue(false)
_actionResultLiveData.postValue(result) _actionResultLiveData.postValue(result)
@ -35,5 +39,11 @@ abstract class ActionViewModelBase(
}) })
} }
override fun onCleared() {
super.onCleared()
disposable.clear()
}
protected abstract fun doExecuteAction(): Single<PumpEnactResult> protected abstract fun doExecuteAction(): Single<PumpEnactResult>
} }

View file

@ -111,13 +111,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
updatePodWarnings() updatePodWarnings()
aapsLogger.info(LTag.PUMP, "statusChecker") aapsLogger.info(LTag.PUMP, "statusChecker")
createFakeTBRWhenNoActivePod() val err = createFakeTBRWhenNoActivePod()
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.subscribeBy( .blockingGet()
onError = { err?.let {
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it")
} }
)
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
} }

View file

@ -17,13 +17,13 @@ class AlertConfiguration(
get() { get() {
var firstByte = (type.index.toInt() shl 4).toByte() var firstByte = (type.index.toInt() shl 4).toByte()
if (enabled) { if (enabled) {
firstByte = firstByte or (1 shl 3).toByte() firstByte = (firstByte.toInt() or (1 shl 3)).toByte()
} }
if (trigger is AlertTrigger.ReservoirVolumeTrigger) { if (trigger is AlertTrigger.ReservoirVolumeTrigger) {
firstByte = firstByte or (1 shl 2).toByte() firstByte = (firstByte.toInt() or (1 shl 2)).toByte()
} }
if (autoOff) { if (autoOff) {
firstByte = firstByte or (1 shl 1).toByte() firstByte = (firstByte.toInt() or (1 shl 1)).toByte()
} }
firstByte = firstByte or ((durationInMinutes.toInt() shr 8 and 0x01).toByte()) firstByte = firstByte or ((durationInMinutes.toInt() shr 8 and 0x01).toByte())
return ByteBuffer.allocate(6) return ByteBuffer.allocate(6)

View file

@ -14,6 +14,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -40,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor(
} else } else
null null
omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,

View file

@ -21,6 +21,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBas
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -36,7 +39,6 @@ class DashInsertCannulaViewModel @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger
) : InsertCannulaViewModel(injector, logger) { ) : InsertCannulaViewModel(injector, logger) {
override fun isPodInAlarm(): Boolean = false // TODO override fun isPodInAlarm(): Boolean = false // TODO
override fun isPodActivationTimeExceeded(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO
@ -63,7 +65,8 @@ class DashInsertCannulaViewModel @Inject constructor(
else else
null null
omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown)
.subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,