From b636eb785b378182193e3b3f4ff44032645c1808 Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 29 Sep 2021 21:58:58 +0200 Subject: [PATCH 1/5] Fix Crash if a missing trigger is found --- .../androidaps/plugins/general/automation/triggers/Trigger.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt index a20bff3c2a..9e43863b78 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt @@ -141,7 +141,7 @@ abstract class Trigger(val injector: HasAndroidInjector) { TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON( data.toString() ) - else -> throw ClassNotFoundException(type) + else -> TriggerConnector(injector) } } From a7f82eb4fbbcaf38ce78835fcf0537a50dc7cd56 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 1 Oct 2021 20:17:54 +0200 Subject: [PATCH 2/5] fix warning --- .../ui/wizard/common/viewmodel/ActionViewModelBase.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt index 91ee56d19d..604eac6d89 100644 --- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt +++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt @@ -7,12 +7,14 @@ import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import io.reactivex.Single +import io.reactivex.disposables.Disposable import io.reactivex.rxkotlin.subscribeBy abstract class ActionViewModelBase( protected val injector: HasAndroidInjector, protected val logger: AAPSLogger ) : ViewModelBase() { + private var disposable: Disposable? = null private val _isActionExecutingLiveData = MutableLiveData(false) val isActionExecutingLiveData: LiveData = _isActionExecutingLiveData @@ -22,7 +24,7 @@ abstract class ActionViewModelBase( fun executeAction() { _isActionExecutingLiveData.postValue(true) - val disposable = doExecuteAction().subscribeBy( + disposable = doExecuteAction().subscribeBy( onSuccess = { result -> _isActionExecutingLiveData.postValue(false) _actionResultLiveData.postValue(result) @@ -35,5 +37,10 @@ abstract class ActionViewModelBase( }) } + override fun onCleared() { + super.onCleared() + disposable?.dispose() + } + protected abstract fun doExecuteAction(): Single } From 45c02b9b1e2f37177c3970c041f40cd2abdbfde7 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sat, 2 Oct 2021 10:29:00 +0200 Subject: [PATCH 3/5] fix warnings --- .../omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt | 1 - .../pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt | 2 -- .../dash/driver/pod/definition/AlertConfiguration.kt | 6 +++--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt index d9fff23aad..12f8ede4e4 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt @@ -180,7 +180,6 @@ class OmnipodDashBleManagerImpl @Inject constructor( ?: throw FailedToConnectException("connection lost") } - @kotlin.ExperimentalStdlibApi override fun pairNewPod(): Observable = Observable.create { emitter -> if (!busy.compareAndSet(false, true)) { throw BusyException() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt index da5a5cbb96..0482a12660 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/LTKExchanger.kt @@ -23,7 +23,6 @@ internal class LTKExchanger( private val keyExchange = KeyExchange(aapsLogger, X25519KeyGenerator(), RandomByteGenerator()) private var seq: Byte = 1 - @kotlin.ExperimentalStdlibApi @Throws(PairingException::class) fun negotiateLTK(): PairResult { val sp1sp2 = PairMessage( @@ -114,7 +113,6 @@ internal class LTKExchanger( keyExchange.validatePodConf(payload) } - @kotlin.ExperimentalStdlibApi private fun sp2(): ByteArray { // This is GetPodStatus command, with page 0 parameter. // We could replace that in the future with the serialized GetPodStatus() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt index 26b0a5c94e..7669f176f7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/AlertConfiguration.kt @@ -17,13 +17,13 @@ class AlertConfiguration( get() { var firstByte = (type.index.toInt() shl 4).toByte() if (enabled) { - firstByte = firstByte or (1 shl 3) + firstByte = (firstByte.toInt() or (1 shl 3)).toByte() } if (trigger is AlertTrigger.ReservoirVolumeTrigger) { - firstByte = firstByte or (1 shl 2) + firstByte = (firstByte.toInt() or (1 shl 2)).toByte() } if (autoOff) { - firstByte = firstByte or (1 shl 1) + firstByte = (firstByte.toInt() or (1 shl 1)).toByte() } firstByte = firstByte or ((durationInMinutes.toInt() shr 8 and 0x01).toByte()) return ByteBuffer.allocate(6) From f79e5eca6f5ecf3d2fe5dfae109d1b6a92cadf6c Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 3 Oct 2021 12:11:41 +0200 Subject: [PATCH 4/5] clear disposables --- .../ui/wizard/common/viewmodel/ActionViewModelBase.kt | 10 ++++++---- .../pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 11 +++++------ .../viewmodel/action/DashInitializePodViewModel.kt | 11 ++++++++++- .../viewmodel/action/DashInsertCannulaViewModel.kt | 10 +++++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt index 604eac6d89..f97a4f7d93 100644 --- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt +++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt @@ -7,14 +7,14 @@ import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import io.reactivex.Single -import io.reactivex.disposables.Disposable +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy abstract class ActionViewModelBase( protected val injector: HasAndroidInjector, protected val logger: AAPSLogger ) : ViewModelBase() { - private var disposable: Disposable? = null + private val disposable = CompositeDisposable() private val _isActionExecutingLiveData = MutableLiveData(false) val isActionExecutingLiveData: LiveData = _isActionExecutingLiveData @@ -24,7 +24,7 @@ abstract class ActionViewModelBase( fun executeAction() { _isActionExecutingLiveData.postValue(true) - disposable = doExecuteAction().subscribeBy( + val subscription = doExecuteAction().subscribeBy( onSuccess = { result -> _isActionExecutingLiveData.postValue(false) _actionResultLiveData.postValue(result) @@ -35,12 +35,14 @@ abstract class ActionViewModelBase( _actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment( throwable.message ?: "Caught exception in while executing action in ActionViewModelBase")) }) + disposable.add(subscription) } override fun onCleared() { super.onCleared() - disposable?.dispose() + disposable.clear() } + protected abstract fun doExecuteAction(): Single } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 83b0796ffe..4f49c6f4f1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -111,13 +111,12 @@ class OmnipodDashPumpPlugin @Inject constructor( updatePodWarnings() aapsLogger.info(LTag.PUMP, "statusChecker") - createFakeTBRWhenNoActivePod() + val err = createFakeTBRWhenNoActivePod() .subscribeOn(aapsSchedulers.io) - .subscribeBy( - onError = { - aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") - } - ) + .blockingGet() + err?.let { + aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") + } handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index a6faa187f4..9bb744fa45 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -14,6 +14,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -25,6 +26,8 @@ class DashInitializePodViewModel @Inject constructor( private val podStateManager: OmnipodDashPodStateManager, private val resourceHelper: ResourceHelper ) : InitializePodViewModel(injector, logger) { + private val disposable = CompositeDisposable() + override fun isPodInAlarm(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO @@ -40,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor( } else null - omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( + val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -61,8 +64,14 @@ class DashInitializePodViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) + disposable.add(subscription) } + override fun onCleared() { + super.onCleared() + disposable.clear() + } + @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_initialize_pod_title diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index 9a3530f443..a8f57536cf 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBas import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -36,6 +37,7 @@ class DashInsertCannulaViewModel @Inject constructor( injector: HasAndroidInjector, logger: AAPSLogger ) : InsertCannulaViewModel(injector, logger) { + private val disposable = CompositeDisposable() override fun isPodInAlarm(): Boolean = false // TODO @@ -63,7 +65,7 @@ class DashInsertCannulaViewModel @Inject constructor( else null - omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( + val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -101,9 +103,15 @@ class DashInsertCannulaViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) + disposable.add(subscription) } } + override fun onCleared() { + super.onCleared() + disposable.clear() + } + @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_insert_cannula_title From a1bd84df1605bde2a1e4e1072457de92e45b4d94 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 3 Oct 2021 16:18:28 +0200 Subject: [PATCH 5/5] cleanup --- .../wizard/common/viewmodel/ActionViewModelBase.kt | 7 ++++--- .../viewmodel/action/DashInitializePodViewModel.kt | 12 +++--------- .../viewmodel/action/DashInsertCannulaViewModel.kt | 13 ++++--------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt index f97a4f7d93..d3c0ac8aaa 100644 --- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt +++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt @@ -8,13 +8,15 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import io.reactivex.Single import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.addTo +import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.subscribeBy abstract class ActionViewModelBase( protected val injector: HasAndroidInjector, protected val logger: AAPSLogger ) : ViewModelBase() { - private val disposable = CompositeDisposable() + protected val disposable = CompositeDisposable() private val _isActionExecutingLiveData = MutableLiveData(false) val isActionExecutingLiveData: LiveData = _isActionExecutingLiveData @@ -24,7 +26,7 @@ abstract class ActionViewModelBase( fun executeAction() { _isActionExecutingLiveData.postValue(true) - val subscription = doExecuteAction().subscribeBy( + disposable += doExecuteAction().subscribeBy( onSuccess = { result -> _isActionExecutingLiveData.postValue(false) _actionResultLiveData.postValue(result) @@ -35,7 +37,6 @@ abstract class ActionViewModelBase( _actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment( throwable.message ?: "Caught exception in while executing action in ActionViewModelBase")) }) - disposable.add(subscription) } override fun onCleared() { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index 9bb744fa45..78f8c48d8d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -15,6 +15,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP 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 javax.inject.Inject @@ -26,8 +28,6 @@ class DashInitializePodViewModel @Inject constructor( private val podStateManager: OmnipodDashPodStateManager, private val resourceHelper: ResourceHelper ) : InitializePodViewModel(injector, logger) { - private val disposable = CompositeDisposable() - override fun isPodInAlarm(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO @@ -43,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor( } else null - val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( + super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -64,14 +64,8 @@ class DashInitializePodViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) - disposable.add(subscription) } - override fun onCleared() { - super.onCleared() - disposable.clear() - } - @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_initialize_pod_title diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index a8f57536cf..a716d2b56b 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -22,6 +22,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP 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 javax.inject.Inject @@ -37,8 +39,6 @@ class DashInsertCannulaViewModel @Inject constructor( injector: HasAndroidInjector, logger: AAPSLogger ) : InsertCannulaViewModel(injector, logger) { - private val disposable = CompositeDisposable() - override fun isPodInAlarm(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO @@ -65,7 +65,8 @@ class DashInsertCannulaViewModel @Inject constructor( else null - val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( + super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown) + .subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -103,15 +104,9 @@ class DashInsertCannulaViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) - disposable.add(subscription) } } - override fun onCleared() { - super.onCleared() - disposable.clear() - } - @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_insert_cannula_title