parent
05047029ea
commit
d49b87d124
|
@ -14,7 +14,6 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.*
|
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.*
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
|
||||||
|
@ -111,11 +110,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPumpStatus(reason: String) {
|
override fun getPumpStatus(reason: String) {
|
||||||
Observable.concat(
|
// TODO history
|
||||||
omnipodManager.getStatus(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE),
|
omnipodManager.getStatus(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE).blockingSubscribeBy(
|
||||||
history.updateFromState(podStateManager).toObservable(),
|
|
||||||
podStateManager.updateActiveCommand().toObservable(),
|
|
||||||
).blockingSubscribeBy(
|
|
||||||
onNext = { podEvent ->
|
onNext = { podEvent ->
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
|
@ -132,12 +128,26 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||||
return executeProgrammingCommand(
|
// TODO history
|
||||||
history.createRecord(
|
|
||||||
commandType = OmnipodCommandType.SET_BASAL_PROFILE
|
return Single.create<PumpEnactResult> { source ->
|
||||||
),
|
omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)).subscribeBy(
|
||||||
omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile))
|
onNext = { podEvent ->
|
||||||
)
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in setNewBasalProfile: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in setNewBasalProfile", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("setNewBasalProfile completed")
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(true).enacted(true))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean = podStateManager.basalProgram?.let {
|
override fun isThisProfileSet(profile: Profile): Boolean = podStateManager.basalProgram?.let {
|
||||||
|
@ -145,7 +155,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
} ?: true
|
} ?: true
|
||||||
|
|
||||||
override fun lastDataTime(): Long {
|
override fun lastDataTime(): Long {
|
||||||
return podStateManager.lastUpdatedSystem
|
return podStateManager.lastConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
override val baseBasalRate: Double
|
override val baseBasalRate: Double
|
||||||
|
@ -201,15 +211,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
},
|
},
|
||||||
onError = { throwable ->
|
onError = { throwable ->
|
||||||
aapsLogger.error(LTag.PUMP, "Error in deliverTreatment", throwable)
|
aapsLogger.error(LTag.PUMP, "Error in deliverTreatment", throwable)
|
||||||
source.onSuccess(
|
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
|
||||||
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
onComplete = {
|
onComplete = {
|
||||||
aapsLogger.debug("deliverTreatment completed")
|
aapsLogger.debug("deliverTreatment completed")
|
||||||
source.onSuccess(
|
source.onSuccess(
|
||||||
PumpEnactResult(injector).success(true).enacted(true)
|
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin)
|
||||||
.bolusDelivered(detailedBolusInfo.insulin)
|
|
||||||
.carbsDelivered(detailedBolusInfo.carbs)
|
.carbsDelivered(detailedBolusInfo.carbs)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -219,9 +226,29 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun stopBolusDelivering() {
|
override fun stopBolusDelivering() {
|
||||||
// TODO update Treatments (?)
|
// TODO update Treatments (?)
|
||||||
executeProgrammingCommand(
|
|
||||||
history.createRecord(OmnipodCommandType.CANCEL_BOLUS),
|
Observable.concat(
|
||||||
|
history.createRecord(
|
||||||
|
commandType = OmnipodCommandType.CANCEL_BOLUS,
|
||||||
|
).flatMapObservable { recordId ->
|
||||||
|
podStateManager.createActiveCommand(recordId).toObservable()
|
||||||
|
},
|
||||||
omnipodManager.stopBolus(),
|
omnipodManager.stopBolus(),
|
||||||
|
history.updateFromState(podStateManager).toObservable(),
|
||||||
|
podStateManager.updateActiveCommand().toObservable(),
|
||||||
|
).blockingSubscribeBy(
|
||||||
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in stopBolusDelivering: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in stopBolusDelivering", throwable)
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("stopBolusDelivering completed")
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,17 +259,41 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
enforceNew: Boolean
|
enforceNew: Boolean
|
||||||
): PumpEnactResult {
|
): PumpEnactResult {
|
||||||
// TODO update Treatments
|
// TODO update Treatments
|
||||||
// TODO check for existing basal
|
|
||||||
return executeProgrammingCommand(
|
return Single.create<PumpEnactResult> { source ->
|
||||||
history.createRecord(
|
Observable.concat(
|
||||||
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
|
history.createRecord(
|
||||||
tempBasalRecord = TempBasalRecord(duration = durationInMinutes, rate = absoluteRate)
|
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
|
||||||
),
|
tempBasalRecord = TempBasalRecord(duration = durationInMinutes, rate = absoluteRate)
|
||||||
omnipodManager.setTempBasal(
|
).flatMapObservable { recordId ->
|
||||||
absoluteRate,
|
podStateManager.createActiveCommand(recordId).toObservable()
|
||||||
durationInMinutes.toShort()
|
},
|
||||||
|
omnipodManager.setTempBasal(
|
||||||
|
absoluteRate,
|
||||||
|
durationInMinutes.toShort()
|
||||||
|
),
|
||||||
|
history.updateFromState(podStateManager).toObservable(),
|
||||||
|
podStateManager.updateActiveCommand().toObservable(),
|
||||||
|
).subscribeBy(
|
||||||
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in setTempBasalAbsolute: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in setTempBasalAbsolute", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("setTempBasalAbsolute completed")
|
||||||
|
source.onSuccess(
|
||||||
|
PumpEnactResult(injector).success(true).enacted(true).absolute(absoluteRate)
|
||||||
|
.duration(durationInMinutes)
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
}.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setTempBasalPercent(
|
override fun setTempBasalPercent(
|
||||||
|
@ -264,10 +315,37 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
|
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
|
||||||
// TODO update Treatments
|
// TODO update Treatments
|
||||||
return executeProgrammingCommand(
|
|
||||||
history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
|
return Single.create<PumpEnactResult> { source ->
|
||||||
omnipodManager.stopTempBasal()
|
|
||||||
)
|
Observable.concat(
|
||||||
|
history.createRecord(
|
||||||
|
commandType = OmnipodCommandType.CANCEL_TEMPORARY_BASAL
|
||||||
|
).flatMapObservable { recordId ->
|
||||||
|
podStateManager.createActiveCommand(recordId).toObservable()
|
||||||
|
},
|
||||||
|
omnipodManager.stopTempBasal(),
|
||||||
|
history.updateFromState(podStateManager).toObservable(),
|
||||||
|
podStateManager.updateActiveCommand().toObservable(),
|
||||||
|
).subscribeBy(
|
||||||
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in cancelTempBasal: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in cancelTempBasal", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("cancelTempBasal completed")
|
||||||
|
source.onSuccess(
|
||||||
|
PumpEnactResult(injector).success(true).enacted(true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancelExtendedBolus(): PumpEnactResult {
|
override fun cancelExtendedBolus(): PumpEnactResult {
|
||||||
|
@ -292,8 +370,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialNumber(): String {
|
override fun serialNumber(): String {
|
||||||
return podStateManager.uniqueId?.toString()
|
return if (podStateManager.uniqueId == null) {
|
||||||
?: "n/a" // TODO i18n
|
"n/a" // TODO i18n
|
||||||
|
} else {
|
||||||
|
podStateManager.uniqueId.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shortStatus(veryShort: Boolean): String {
|
override fun shortStatus(veryShort: Boolean): String {
|
||||||
|
@ -352,15 +433,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun silenceAlerts(): PumpEnactResult {
|
private fun silenceAlerts(): PumpEnactResult {
|
||||||
|
// TODO history
|
||||||
// TODO filter alert types
|
// TODO filter alert types
|
||||||
|
|
||||||
return podStateManager.activeAlerts?.let {
|
return podStateManager.activeAlerts?.let {
|
||||||
Single.create<PumpEnactResult> { source ->
|
Single.create<PumpEnactResult> { source ->
|
||||||
Observable.concat(
|
omnipodManager.silenceAlerts(it).subscribeBy(
|
||||||
// TODO: is this a programming command? if yes, save to history
|
|
||||||
omnipodManager.silenceAlerts(it),
|
|
||||||
history.updateFromState(podStateManager).toObservable(),
|
|
||||||
podStateManager.updateActiveCommand().toObservable(),
|
|
||||||
).subscribeBy(
|
|
||||||
onNext = { podEvent ->
|
onNext = { podEvent ->
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
|
@ -381,26 +459,75 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun suspendDelivery(): PumpEnactResult {
|
private fun suspendDelivery(): PumpEnactResult {
|
||||||
return executeProgrammingCommand(
|
// TODO history
|
||||||
history.createRecord(OmnipodCommandType.RESUME_DELIVERY),
|
|
||||||
omnipodManager.suspendDelivery()
|
return Single.create<PumpEnactResult> { source ->
|
||||||
)
|
omnipodManager.suspendDelivery().subscribeBy(
|
||||||
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in suspendDelivery: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in suspendDelivery", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("suspendDelivery completed")
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resumeDelivery(): PumpEnactResult {
|
private fun resumeDelivery(): PumpEnactResult {
|
||||||
|
// TODO history
|
||||||
|
|
||||||
return profileFunction.getProfile()?.let {
|
return profileFunction.getProfile()?.let {
|
||||||
executeProgrammingCommand(
|
|
||||||
history.createRecord(OmnipodCommandType.RESUME_DELIVERY),
|
Single.create<PumpEnactResult> { source ->
|
||||||
omnipodManager.setBasalProgram(mapProfileToBasalProgram(it))
|
omnipodManager.setBasalProgram(mapProfileToBasalProgram(it)).subscribeBy(
|
||||||
)
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in resumeDelivery: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in resumeDelivery", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("resumeDelivery completed")
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}.blockingGet()
|
||||||
} ?: PumpEnactResult(injector).success(false).enacted(false).comment("No profile active") // TODO i18n
|
} ?: PumpEnactResult(injector).success(false).enacted(false).comment("No profile active") // TODO i18n
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deactivatePod(): PumpEnactResult {
|
private fun deactivatePod(): PumpEnactResult {
|
||||||
return executeProgrammingCommand(
|
// TODO history
|
||||||
history.createRecord(OmnipodCommandType.DEACTIVATE_POD),
|
|
||||||
omnipodManager.deactivatePod()
|
return Single.create<PumpEnactResult> { source ->
|
||||||
)
|
omnipodManager.deactivatePod().subscribeBy(
|
||||||
|
onNext = { podEvent ->
|
||||||
|
aapsLogger.debug(
|
||||||
|
LTag.PUMP,
|
||||||
|
"Received PodEvent in deactivatePod: $podEvent"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = { throwable ->
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error in deactivatePod", throwable)
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.message))
|
||||||
|
},
|
||||||
|
onComplete = {
|
||||||
|
aapsLogger.debug("deactivatePod completed")
|
||||||
|
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleTimeChange(): PumpEnactResult {
|
private fun handleTimeChange(): PumpEnactResult {
|
||||||
|
@ -414,13 +541,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playTestBeep(): PumpEnactResult {
|
private fun playTestBeep(): PumpEnactResult {
|
||||||
|
// TODO history
|
||||||
|
|
||||||
return Single.create<PumpEnactResult> { source ->
|
return Single.create<PumpEnactResult> { source ->
|
||||||
Observable.concat(
|
omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP).subscribeBy(
|
||||||
omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP),
|
|
||||||
history.updateFromState(podStateManager).toObservable(),
|
|
||||||
podStateManager.updateActiveCommand().toObservable(),
|
|
||||||
).subscribeBy(
|
|
||||||
onNext = { podEvent ->
|
onNext = { podEvent ->
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
|
@ -429,9 +553,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
},
|
},
|
||||||
onError = { throwable ->
|
onError = { throwable ->
|
||||||
aapsLogger.error(LTag.PUMP, "Error in playTestBeep", throwable)
|
aapsLogger.error(LTag.PUMP, "Error in playTestBeep", throwable)
|
||||||
source.onSuccess(
|
source.onSuccess(PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message))
|
||||||
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
onComplete = {
|
onComplete = {
|
||||||
aapsLogger.debug("playTestBeep completed")
|
aapsLogger.debug("playTestBeep completed")
|
||||||
|
@ -463,39 +585,4 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
commandQueue.customCommand(CommandHandleTimeChange(false), null)
|
commandQueue.customCommand(CommandHandleTimeChange(false), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun executeProgrammingCommand(
|
|
||||||
historyEntry: Single<String>,
|
|
||||||
command: Observable<PodEvent>
|
|
||||||
): PumpEnactResult {
|
|
||||||
return Single.create<PumpEnactResult> { source ->
|
|
||||||
Observable.concat(
|
|
||||||
historyEntry.flatMapObservable { recordId ->
|
|
||||||
podStateManager.createActiveCommand(recordId).toObservable()
|
|
||||||
},
|
|
||||||
command,
|
|
||||||
history.updateFromState(podStateManager).toObservable(),
|
|
||||||
podStateManager.updateActiveCommand().toObservable(),
|
|
||||||
).subscribeBy(
|
|
||||||
onNext = { podEvent ->
|
|
||||||
aapsLogger.debug(
|
|
||||||
LTag.PUMP,
|
|
||||||
"Received PodEvent: $podEvent"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onError = { throwable ->
|
|
||||||
aapsLogger.error(LTag.PUMP, "Error executing command", throwable)
|
|
||||||
source.onSuccess(
|
|
||||||
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onComplete = {
|
|
||||||
aapsLogger.debug("Command completed")
|
|
||||||
source.onSuccess(
|
|
||||||
PumpEnactResult(injector).success(true).enacted(true)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}.blockingGet()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue