fix alerts(UNKNOWN will always match)

This commit is contained in:
Andrei Vereha 2021-06-06 13:09:27 +02:00
parent 79b4a5d656
commit d82be68796
2 changed files with 14 additions and 31 deletions

View file

@ -293,10 +293,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun stopBolusDelivering() { override fun stopBolusDelivering() {
// TODO update Treatments (?) // TODO update Treatments (?)
executeProgrammingCommand( aapsLogger.info(LTag.PUMP, "stopBolusDelivering called")
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(
@ -440,6 +442,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()
} }
@ -528,33 +533,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)