Merge branch 'avereha/alarms' into avereha/bolus

This commit is contained in:
Andrei Vereha 2021-06-06 13:11:16 +02:00
commit 4f459b9fc1
2 changed files with 13 additions and 31 deletions

View file

@ -339,10 +339,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun stopBolusDelivering() { override fun stopBolusDelivering() {
// TODO update Treatments (?) // TODO update Treatments (?)
aapsLogger.info(LTag.PUMP, "stopBolusDelivering called") aapsLogger.info(LTag.PUMP, "stopBolusDelivering called")
executeProgrammingCommand( val ret = executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.CANCEL_BOLUS), historyEntry = history.createRecord(OmnipodCommandType.CANCEL_BOLUS),
command = omnipodManager.stopBolus().ignoreElements() command = omnipodManager.stopBolus().ignoreElements()
).toPumpEnactResult() ).toPumpEnactResult()
aapsLogger.info(LTag.PUMP, "stopBolusDelivering finished with result: $ret")
} }
override fun setTempBasalAbsolute( override fun setTempBasalAbsolute(
@ -487,6 +488,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
fun Completable.toPumpEnactResult(): PumpEnactResult { fun Completable.toPumpEnactResult(): PumpEnactResult {
return this.toSingleDefault(PumpEnactResult(injector).success(true).enacted(true)) return this.toSingleDefault(PumpEnactResult(injector).success(true).enacted(true))
.doOnError { throwable ->
aapsLogger.error(LTag.PUMP, "toPumpEnactResult, error executing command: $throwable")
}
.onErrorReturnItem(PumpEnactResult(injector).success(false).enacted(false)) .onErrorReturnItem(PumpEnactResult(injector).success(false).enacted(false))
.blockingGet() .blockingGet()
} }
@ -575,33 +579,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
private fun silenceAlerts(): PumpEnactResult { private fun silenceAlerts(): PumpEnactResult {
// TODO filter alert types // TODO filter alert types
return podStateManager.activeAlerts?.let { return podStateManager.activeAlerts?.let {
Single.create<PumpEnactResult> { source -> executeProgrammingCommand(
Observable.concat( historyEntry = history.createRecord(commandType = OmnipodCommandType.ACKNOWLEDGE_ALERTS),
// TODO: is this a programming command? if yes, save to history command = omnipodManager.silenceAlerts(it).ignoreElements(),
omnipodManager.silenceAlerts(it), ).toPumpEnactResult()
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
).subscribeBy(
onNext = { podEvent ->
aapsLogger.debug(
LTag.PUMP,
"Received PodEvent in silenceAlerts: $podEvent"
)
},
onError = { throwable ->
aapsLogger.error(LTag.PUMP, "Error in silenceAlerts", throwable)
source.onSuccess(
PumpEnactResult(injector).success(false).comment(
throwable.toString()
)
)
},
onComplete = {
aapsLogger.debug("silenceAlerts completed")
source.onSuccess(PumpEnactResult(injector).success(true))
}
)
}.blockingGet()
} ?: PumpEnactResult(injector).success(false).enacted(false).comment("No active alerts") // TODO i18n } ?: PumpEnactResult(injector).success(false).enacted(false).comment("No active alerts") // TODO i18n
} }

View file

@ -8,9 +8,10 @@ object AlertUtil {
fun decodeAlertSet(encoded: Byte): EnumSet<AlertType> { fun decodeAlertSet(encoded: Byte): EnumSet<AlertType> {
val encodedInt = encoded.toInt() and 0xff val encodedInt = encoded.toInt() and 0xff
val alertList = AlertType.values().filter { val alertList = AlertType.values()
(it.value.toInt() and 0xff) and encodedInt != 0 .filter { it != AlertType.UNKNOWN } // 0xff && <something> will always be true
}.toList() .filter { (it.value.toInt() and 0xff) and encodedInt != 0 }
.toList()
return if (alertList.isEmpty()) { return if (alertList.isEmpty()) {
EnumSet.noneOf(AlertType::class.java) EnumSet.noneOf(AlertType::class.java)