Fix EB sync
This commit is contained in:
parent
28a6a0a8ab
commit
3739db489f
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||||
import info.nightscout.androidaps.receivers.DataWorker
|
import info.nightscout.androidaps.receivers.DataWorker
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
|
@ -47,6 +48,7 @@ class NSClientAddUpdateWorker(
|
||||||
@Inject lateinit var activePlugin: ActivePlugin
|
@Inject lateinit var activePlugin: ActivePlugin
|
||||||
@Inject lateinit var rxBus: RxBus
|
@Inject lateinit var rxBus: RxBus
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
||||||
|
@ -60,7 +62,7 @@ class NSClientAddUpdateWorker(
|
||||||
// new DB model
|
// new DB model
|
||||||
val insulin = JsonHelper.safeGetDouble(json, "insulin")
|
val insulin = JsonHelper.safeGetDouble(json, "insulin")
|
||||||
val carbs = JsonHelper.safeGetDouble(json, "carbs")
|
val carbs = JsonHelper.safeGetDouble(json, "carbs")
|
||||||
val eventType = JsonHelper.safeGetString(json, "eventType")
|
var eventType = JsonHelper.safeGetString(json, "eventType")
|
||||||
if (eventType == null) {
|
if (eventType == null) {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Wrong treatment. Ignoring : $json")
|
aapsLogger.debug(LTag.NSCLIENT, "Wrong treatment. Ignoring : $json")
|
||||||
continue
|
continue
|
||||||
|
@ -138,7 +140,10 @@ class NSClientAddUpdateWorker(
|
||||||
val ebJson = json.getJSONObject("extendedEmulated")
|
val ebJson = json.getJSONObject("extendedEmulated")
|
||||||
ebJson.put("_id", json.getString("_id"))
|
ebJson.put("_id", json.getString("_id"))
|
||||||
ebJson.put("isValid", json.getBoolean("isValid"))
|
ebJson.put("isValid", json.getBoolean("isValid"))
|
||||||
|
ebJson.put("mills", mills)
|
||||||
json = ebJson
|
json = ebJson
|
||||||
|
eventType = JsonHelper.safeGetString(json, "eventType")
|
||||||
|
virtualPumpPlugin.fakeDataDetected = true
|
||||||
}
|
}
|
||||||
when {
|
when {
|
||||||
insulin > 0 || carbs > 0 -> Any()
|
insulin > 0 || carbs > 0 -> Any()
|
||||||
|
|
|
@ -78,7 +78,7 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
it.isExtendedBolusCapable = true
|
it.isExtendedBolusCapable = true
|
||||||
it.extendedBolusStep = 0.05
|
it.extendedBolusStep = 0.05
|
||||||
it.extendedBolusDurationStep = 30.0
|
it.extendedBolusDurationStep = 30.0
|
||||||
it.extendedBolusMaxDuration = 8 * 60.toDouble()
|
it.extendedBolusMaxDuration = 8 * 60.0
|
||||||
it.isTempBasalCapable = true
|
it.isTempBasalCapable = true
|
||||||
it.tempBasalStyle = PumpDescription.PERCENT or PumpDescription.ABSOLUTE
|
it.tempBasalStyle = PumpDescription.PERCENT or PumpDescription.ABSOLUTE
|
||||||
it.maxTempPercent = 500
|
it.maxTempPercent = 500
|
||||||
|
@ -95,14 +95,6 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
it.is30minBasalRatesCapable = true
|
it.is30minBasalRatesCapable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFakingStatus(): Boolean {
|
|
||||||
return sp.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setFakingStatus(newStatus: Boolean) {
|
|
||||||
sp.putBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, newStatus)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
|
@ -125,7 +117,8 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override val isFakingTempsByExtendedBoluses: Boolean
|
override val isFakingTempsByExtendedBoluses: Boolean
|
||||||
get() = config.NSCLIENT && getFakingStatus()
|
get() = config.NSCLIENT && fakeDataDetected
|
||||||
|
var fakeDataDetected = false
|
||||||
|
|
||||||
override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future?
|
override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future?
|
||||||
return PumpEnactResult(injector)
|
return PumpEnactResult(injector)
|
||||||
|
@ -156,14 +149,9 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
return PumpEnactResult(injector).success(true).enacted(true)
|
return PumpEnactResult(injector).success(true).enacted(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean {
|
override fun isThisProfileSet(profile: Profile): Boolean = pumpSync.expectedPumpState().profile?.isEqual(profile) ?: false
|
||||||
val running = pumpSync.expectedPumpState().profile
|
|
||||||
return running?.isEqual(profile) ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun lastDataTime(): Long {
|
override fun lastDataTime(): Long = lastDataTime
|
||||||
return lastDataTime
|
|
||||||
}
|
|
||||||
|
|
||||||
override val baseBasalRate: Double
|
override val baseBasalRate: Double
|
||||||
get() = profileFunction.getProfile()?.getBasal() ?: 0.0
|
get() = profileFunction.getProfile()?.getBasal() ?: 0.0
|
||||||
|
@ -373,25 +361,15 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
return pump
|
return pump
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun manufacturer(): ManufacturerType {
|
override fun manufacturer(): ManufacturerType = pumpDescription.pumpType.manufacturer ?: ManufacturerType.AndroidAPS
|
||||||
return pumpDescription.pumpType.manufacturer ?: ManufacturerType.AndroidAPS
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun model(): PumpType {
|
override fun model(): PumpType = pumpDescription.pumpType
|
||||||
return pumpDescription.pumpType
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun serialNumber(): String {
|
override fun serialNumber(): String = instanceId()
|
||||||
return instanceId()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun shortStatus(veryShort: Boolean): String {
|
override fun shortStatus(veryShort: Boolean): String = "Virtual Pump"
|
||||||
return "Virtual Pump"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canHandleDST(): Boolean {
|
override fun canHandleDST(): Boolean = true
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refreshConfiguration() {
|
fun refreshConfiguration() {
|
||||||
val pumpType = sp.getString(R.string.key_virtualpump_type, PumpType.GENERIC_AAPS.description)
|
val pumpType = sp.getString(R.string.key_virtualpump_type, PumpType.GENERIC_AAPS.description)
|
||||||
|
@ -404,5 +382,4 @@ open class VirtualPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,7 +698,6 @@
|
||||||
<string name="no_action_selected">No action selected, nothing will happen</string>
|
<string name="no_action_selected">No action selected, nothing will happen</string>
|
||||||
<string name="start_hypo_tt">Start Hypo TT</string>
|
<string name="start_hypo_tt">Start Hypo TT</string>
|
||||||
<string name="closed_loop_disabled_on_dev_branch">Running dev version. Closed loop is disabled.</string>
|
<string name="closed_loop_disabled_on_dev_branch">Running dev version. Closed loop is disabled.</string>
|
||||||
<string name="key_fromNSAreCommingFakedExtendedBoluses" translatable="false">fromNSAreCommingFakedExtendedBoluses</string>
|
|
||||||
<string name="engineering_mode_enabled">Engineering mode enabled</string>
|
<string name="engineering_mode_enabled">Engineering mode enabled</string>
|
||||||
<string name="profileswitch_ismissing">ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile.</string>
|
<string name="profileswitch_ismissing">ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile.</string>
|
||||||
<string name="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
<string name="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
||||||
|
|
|
@ -29,6 +29,7 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) :
|
||||||
}
|
}
|
||||||
if (current.duration != extendedBolus.duration) {
|
if (current.duration != extendedBolus.duration) {
|
||||||
current.duration = extendedBolus.duration
|
current.duration = extendedBolus.duration
|
||||||
|
current.amount = extendedBolus.amount
|
||||||
database.extendedBolusDao.updateExistingEntry(current)
|
database.extendedBolusDao.updateExistingEntry(current)
|
||||||
result.updatedDuration.add(current)
|
result.updatedDuration.add(current)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue