getJSONstatus. format
This commit is contained in:
parent
00de96cba3
commit
058ed9d79f
8 changed files with 120 additions and 84 deletions
|
@ -11,6 +11,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange
|
|||
import info.nightscout.androidaps.events.EventProfileSwitchChanged
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||
import info.nightscout.androidaps.extensions.convertedToAbsolute
|
||||
import info.nightscout.androidaps.extensions.plannedRemainingMinutes
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -40,6 +42,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
|
||||
import info.nightscout.androidaps.queue.commands.Command
|
||||
import info.nightscout.androidaps.queue.commands.CustomCommand
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.TimeChangeType
|
||||
|
@ -51,6 +54,7 @@ import io.reactivex.Single
|
|||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import org.json.JSONObject
|
||||
import java.lang.Exception
|
||||
import java.time.Duration
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.*
|
||||
|
@ -73,6 +77,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
private val context: Context,
|
||||
private val aapsSchedulers: AapsSchedulers,
|
||||
private val fabricPrivacy: FabricPrivacy,
|
||||
private val dateUtil: DateUtil,
|
||||
|
||||
injector: HasAndroidInjector,
|
||||
aapsLogger: AAPSLogger,
|
||||
|
@ -84,7 +89,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var statusChecker: Runnable
|
||||
var nextPodWarningCheck: Long = 0
|
||||
private var nextPodWarningCheck: Long = 0
|
||||
@Volatile var stopConnecting: CountDownLatch? = null
|
||||
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -574,7 +579,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
).filter { podEvent -> podEvent.isCommandSent() }
|
||||
.map { pumpSyncBolusStart(requestedBolusAmount, detailedBolusInfo.bolusType) }
|
||||
.ignoreElements(),
|
||||
post = waitForBolusDeliveryToComplete(BOLUS_RETRIES, requestedBolusAmount, detailedBolusInfo.bolusType)
|
||||
post = waitForBolusDeliveryToComplete(requestedBolusAmount, detailedBolusInfo.bolusType)
|
||||
.map {
|
||||
deliveredBolusAmount = it
|
||||
aapsLogger.info(LTag.PUMP, "deliverTreatment: deliveredBolusAmount=$deliveredBolusAmount")
|
||||
|
@ -638,14 +643,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun waitForBolusDeliveryToComplete(
|
||||
maxTries: Int,
|
||||
requestedBolusAmount: Double,
|
||||
bolusType: DetailedBolusInfo.BolusType
|
||||
): Single<Double> = Single.defer {
|
||||
|
||||
if (bolusCanceled && podStateManager.activeCommand != null) {
|
||||
var errorGettingStatus: Throwable? = null
|
||||
for (tries in 1..maxTries) {
|
||||
for (tries in 1..BOLUS_RETRIES) {
|
||||
errorGettingStatus = getPodStatus().blockingGet()
|
||||
if (errorGettingStatus != null) {
|
||||
aapsLogger.debug(LTag.PUMP, "waitForBolusDeliveryToComplete errorGettingStatus=$errorGettingStatus")
|
||||
|
@ -676,7 +680,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
for (tryNumber in 1..maxTries) {
|
||||
for (tryNumber in 1..BOLUS_RETRIES) {
|
||||
updateBolusProgressDialog("Checking delivery status", 100)
|
||||
|
||||
val cmd = if (bolusCanceled)
|
||||
|
@ -778,7 +782,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
)
|
||||
|
||||
val ret = executeProgrammingCommand(
|
||||
pre = observeNoActiveTempBasal(true),
|
||||
pre = observeNoActiveTempBasal(),
|
||||
historyEntry = history.createRecord(
|
||||
commandType = OmnipodCommandType.SET_TEMPORARY_BASAL,
|
||||
tempBasalRecord = TempBasalRecord(duration = durationInMinutes, rate = absoluteRate)
|
||||
|
@ -848,24 +852,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
return ret
|
||||
}
|
||||
|
||||
private fun observeNoActiveTempBasal(enforceNew: Boolean): Completable {
|
||||
private fun observeNoActiveTempBasal(): Completable {
|
||||
return Completable.defer {
|
||||
when {
|
||||
podStateManager.deliveryStatus !in
|
||||
arrayOf(DeliveryStatus.TEMP_BASAL_ACTIVE, DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE) -> {
|
||||
if (podStateManager.deliveryStatus !in
|
||||
arrayOf(DeliveryStatus.TEMP_BASAL_ACTIVE, DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE)
|
||||
) {
|
||||
// TODO: what happens if we try to cancel nonexistent temp basal?
|
||||
aapsLogger.info(LTag.PUMP, "No temporary basal to cancel")
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
!enforceNew ->
|
||||
Completable.error(
|
||||
IllegalStateException(
|
||||
"Temporary basal already active and enforceNew is not set."
|
||||
)
|
||||
)
|
||||
|
||||
else -> {
|
||||
} else {
|
||||
// enforceNew == true
|
||||
aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
|
||||
executeProgrammingCommand(
|
||||
|
@ -883,7 +878,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setTempBasalPercent(
|
||||
percent: Int,
|
||||
|
@ -954,9 +948,54 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject {
|
||||
// TODO
|
||||
val now = System.currentTimeMillis()
|
||||
if (podStateManager.lastUpdatedSystem + 60 * 60 * 1000L < now) {
|
||||
return JSONObject()
|
||||
}
|
||||
val pumpJson = JSONObject()
|
||||
val status = JSONObject()
|
||||
val extended = JSONObject()
|
||||
try {
|
||||
val podStatus = when {
|
||||
podStateManager.isPodRunning && podStateManager.isSuspended ->
|
||||
"suspended"
|
||||
podStateManager.isPodRunning ->
|
||||
"normal"
|
||||
else ->
|
||||
"no active Pod"
|
||||
}
|
||||
status.put("status", podStatus)
|
||||
status.put("timestamp", dateUtil.toISOString(podStateManager.lastUpdatedSystem))
|
||||
|
||||
extended.put("Version", version)
|
||||
try {
|
||||
extended.put("ActiveProfile", profileName)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
val tb = pumpSync.expectedPumpState().temporaryBasal
|
||||
tb?.run {
|
||||
extended.put("TempBasalAbsoluteRate", this.convertedToAbsolute(now, profile))
|
||||
extended.put("TempBasalStart", dateUtil.dateAndTimeString(this.timestamp))
|
||||
extended.put("TempBasalRemaining", this.plannedRemainingMinutes)
|
||||
}
|
||||
podStateManager.lastBolus?.run {
|
||||
extended.put("LastBolus", dateUtil.dateAndTimeString(this.startTime))
|
||||
extended.put("LastBolusAmount", this.deliveredUnits() ?: this.requestedUnits)
|
||||
}
|
||||
extended.put("BaseBasalRate", baseBasalRate)
|
||||
|
||||
pumpJson.put("status", status)
|
||||
pumpJson.put("extended", extended)
|
||||
if (podStateManager.pulsesRemaining == null) {
|
||||
pumpJson.put("reservoir_display_override", "50+")
|
||||
}
|
||||
pumpJson.put("reservoir", reservoirLevel.toInt())
|
||||
pumpJson.put("clock", dateUtil.toISOString(now))
|
||||
} catch (e: Exception) {
|
||||
aapsLogger.error(LTag.PUMP, "Unhandled exception: $e")
|
||||
}
|
||||
return pumpJson
|
||||
}
|
||||
|
||||
override val pumpDescription: PumpDescription = Companion.pumpDescription
|
||||
|
||||
|
@ -1348,7 +1387,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
pumpId = historyEntry.pumpId(),
|
||||
pumpType = PumpType.OMNIPOD_DASH,
|
||||
pumpSerial = serialNumber(),
|
||||
type = null // TODO: set the correct bolus type here!!!
|
||||
type = null
|
||||
)
|
||||
}
|
||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_UNCERTAIN_SMB))
|
||||
|
|
|
@ -9,9 +9,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.*
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.GetVersionCommand.Companion.DEFAULT_UNIQUE_ID
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.MAX_POD_LIFETIME
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS_DURATION
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_IMMINENT_ALERT_HOURS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants.Companion.POD_EXPIRATION_ALERT_HOURS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
|
||||
|
||||
import java.time.Duration
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class PodConstants {
|
||||
companion object {
|
||||
|
|
|
@ -5,7 +5,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util.AlertUtil
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util.byValue
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Flag
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.*
|
||||
import kotlin.experimental.and
|
||||
|
|
|
@ -629,8 +629,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
override fun connectionSuccessRatio(): Float {
|
||||
if (connectionAttempts == 0) {
|
||||
return 0.0F
|
||||
}
|
||||
else if (connectionAttempts <= successfulConnections) {
|
||||
} else if (connectionAttempts <= successfulConnections) {
|
||||
// Prevent bogus quality > 1 during initialisation
|
||||
return 1.0F
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodD
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.databinding.OmnipodDashOverviewBluetoothStatusBinding
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodConstants
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
|
|
Loading…
Reference in a new issue