Merge pull request #1403 from avereha/avereha/fix-crash

fix crash
This commit is contained in:
Milos Kozak 2022-03-02 23:50:41 +01:00 committed by GitHub
commit 4f82a23c25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,8 +16,6 @@ import info.nightscout.androidaps.extensions.convertedToAbsolute
import info.nightscout.androidaps.extensions.plannedRemainingMinutes import info.nightscout.androidaps.extensions.plannedRemainingMinutes
import info.nightscout.androidaps.extensions.toStringFull import info.nightscout.androidaps.extensions.toStringFull
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.common.ManufacturerType import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
@ -52,6 +50,8 @@ import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.TimeChangeType import info.nightscout.androidaps.utils.TimeChangeType
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
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 info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
@ -119,10 +119,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
updatePodWarnings() updatePodWarnings()
aapsLogger.info(LTag.PUMP, "statusChecker") aapsLogger.info(LTag.PUMP, "statusChecker")
try {
createFakeTBRWhenNoActivePod() createFakeTBRWhenNoActivePod()
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.doOnError { aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") } .blockingAwait()
.blockingSubscribe() } catch (e: Exception) {
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$e")
}
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
} }
@ -247,10 +250,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
try { try {
stopConnecting?.let { stopConnecting?.let {
omnipodManager.connect(it).ignoreElements() omnipodManager.connect(it).ignoreElements()
.doOnError { aapsLogger.info(LTag.PUMPCOMM, "connect error=$it") }
.doOnComplete { podStateManager.incrementSuccessfulConnectionAttemptsAfterRetries() } .doOnComplete { podStateManager.incrementSuccessfulConnectionAttemptsAfterRetries() }
.blockingSubscribe() .blockingAwait()
} }
} catch (e: Exception) {
aapsLogger.info(LTag.PUMPCOMM, "connect error=$e")
} finally { } finally {
synchronized(this) { synchronized(this) {
stopConnecting = null stopConnecting = null
@ -279,6 +283,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
return return
} }
try {
getPodStatus() getPodStatus()
.doOnComplete { .doOnComplete {
aapsLogger.info(LTag.PUMP, "getPumpStatus executed with success") aapsLogger.info(LTag.PUMP, "getPumpStatus executed with success")
@ -289,11 +294,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
aapsLogger.info(LTag.PUMP, "recoverActivationFromPodStatus msg=$msg") aapsLogger.info(LTag.PUMP, "recoverActivationFromPodStatus msg=$msg")
} }
} }
}.blockingAwait()
} catch (e: Exception) {
aapsLogger.error(LTag.PUMP, "Error in getPumpStatus", e)
} }
.doOnError {
aapsLogger.error(LTag.PUMP, "Error in getPumpStatus", it)
}
.blockingSubscribe()
} }
private fun getPodStatus(): Completable = Completable.concat( private fun getPodStatus(): Completable = Completable.concat(
@ -564,7 +568,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
.comment(rh.gs(R.string.omnipod_dash_not_enough_insulin)) .comment(rh.gs(R.string.omnipod_dash_not_enough_insulin))
} }
if (podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_BASAL_ACTIVE || if (podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_BASAL_ACTIVE ||
podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE) { podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE
) {
return PumpEnactResult(injector) return PumpEnactResult(injector)
.success(false) .success(false)
.enacted(false) .enacted(false)
@ -722,13 +727,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
getPodStatus() getPodStatus()
var errorGettingStatus: Throwable? = null var errorGettingStatus: Throwable? = null
cmd try {
.doOnError { cmd.blockingAwait()
errorGettingStatus = it } catch (e: Exception) {
errorGettingStatus = e
aapsLogger.debug(LTag.PUMP, "waitForBolusDeliveryToComplete errorGettingStatus=$errorGettingStatus") aapsLogger.debug(LTag.PUMP, "waitForBolusDeliveryToComplete errorGettingStatus=$errorGettingStatus")
Thread.sleep(BOLUS_RETRY_INTERVAL_MS) // retry every 3 sec Thread.sleep(BOLUS_RETRY_INTERVAL_MS) // retry every 3 sec
} }
.blockingSubscribe()
if (errorGettingStatus != null) { if (errorGettingStatus != null) {
continue continue
} }