EOPATCH2: jsonStatus
This commit is contained in:
parent
0873df5f56
commit
0fcb9cb4d2
1 changed files with 53 additions and 14 deletions
|
@ -14,6 +14,7 @@ import info.nightscout.interfaces.notifications.Notification
|
||||||
import info.nightscout.interfaces.plugin.PluginDescription
|
import info.nightscout.interfaces.plugin.PluginDescription
|
||||||
import info.nightscout.interfaces.plugin.PluginType
|
import info.nightscout.interfaces.plugin.PluginType
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||||
import info.nightscout.interfaces.pump.Pump
|
import info.nightscout.interfaces.pump.Pump
|
||||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||||
|
@ -42,6 +43,7 @@ import info.nightscout.shared.utils.T
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.functions.Consumer
|
import io.reactivex.rxjava3.functions.Consumer
|
||||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||||
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -63,7 +65,8 @@ class EopatchPumpPlugin @Inject constructor(
|
||||||
private val patchManager: IPatchManager,
|
private val patchManager: IPatchManager,
|
||||||
private val alarmManager: IAlarmManager,
|
private val alarmManager: IAlarmManager,
|
||||||
private val preferenceManager: IPreferenceManager,
|
private val preferenceManager: IPreferenceManager,
|
||||||
private val uiInteraction: UiInteraction
|
private val uiInteraction: UiInteraction,
|
||||||
|
private val profileFunction: ProfileFunction
|
||||||
) : PumpPluginBase(
|
) : PumpPluginBase(
|
||||||
PluginDescription()
|
PluginDescription()
|
||||||
.mainType(PluginType.PUMP)
|
.mainType(PluginType.PUMP)
|
||||||
|
@ -211,11 +214,11 @@ class EopatchPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
aapsLogger.info(LTag.PUMP, "Basal Profile was set: ${isSuccess ?: false}")
|
aapsLogger.info(LTag.PUMP, "Basal Profile was set: ${isSuccess ?: false}")
|
||||||
if (isSuccess == true) {
|
return if (isSuccess == true) {
|
||||||
uiInteraction.addNotificationValidFor(Notification.PROFILE_SET_OK, rh.gs(info.nightscout.core.ui.R.string.profile_set_ok), Notification.INFO, 60)
|
uiInteraction.addNotificationValidFor(Notification.PROFILE_SET_OK, rh.gs(info.nightscout.core.ui.R.string.profile_set_ok), Notification.INFO, 60)
|
||||||
return PumpEnactResult(injector).success(true).enacted(true)
|
PumpEnactResult(injector).success(true).enacted(true)
|
||||||
} else {
|
} else {
|
||||||
return PumpEnactResult(injector)
|
PumpEnactResult(injector)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
preferenceManager.getNormalBasalManager().setNormalBasal(profile)
|
preferenceManager.getNormalBasalManager().setNormalBasal(profile)
|
||||||
|
@ -498,7 +501,43 @@ class EopatchPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject {
|
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject {
|
||||||
return JSONObject()
|
val now = System.currentTimeMillis()
|
||||||
|
val pumpJson = JSONObject()
|
||||||
|
val battery = JSONObject()
|
||||||
|
val status = JSONObject()
|
||||||
|
val extended = JSONObject()
|
||||||
|
try {
|
||||||
|
battery.put("percent", 100)
|
||||||
|
status.put("status", if (patchManager.patchState.isNormalBasalPaused) "suspended" else "normal")
|
||||||
|
status.put("timestamp", dateUtil.toISOString(lastDataTime()))
|
||||||
|
extended.put("Version", version)
|
||||||
|
val tb = pumpSync.expectedPumpState().temporaryBasal
|
||||||
|
if (tb != null) {
|
||||||
|
extended.put("TempBasalAbsoluteRate", tb.convertedToAbsolute(now, profile))
|
||||||
|
extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.timestamp))
|
||||||
|
extended.put("TempBasalRemaining", tb.plannedRemainingMinutes)
|
||||||
|
}
|
||||||
|
val eb = pumpSync.expectedPumpState().extendedBolus
|
||||||
|
if (eb != null) {
|
||||||
|
extended.put("ExtendedBolusAbsoluteRate", eb.rate)
|
||||||
|
extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.timestamp))
|
||||||
|
extended.put("ExtendedBolusRemaining", eb.plannedRemainingMinutes)
|
||||||
|
}
|
||||||
|
extended.put("BaseBasalRate", baseBasalRate)
|
||||||
|
try {
|
||||||
|
extended.put("ActiveProfile", profileFunction.getProfileName())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
aapsLogger.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
pumpJson.put("battery", battery)
|
||||||
|
pumpJson.put("status", status)
|
||||||
|
pumpJson.put("extended", extended)
|
||||||
|
pumpJson.put("reservoir", patchManager.patchState.remainedInsulin.toInt())
|
||||||
|
pumpJson.put("clock", dateUtil.toISOString(now))
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
aapsLogger.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
return pumpJson
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun manufacturer(): ManufacturerType {
|
override fun manufacturer(): ManufacturerType {
|
||||||
|
|
Loading…
Reference in a new issue