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.general.overview.events.EventNewNotification
|
||||
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.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
|
@ -47,6 +48,7 @@ class NSClientAddUpdateWorker(
|
|||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
|
||||
|
||||
override fun doWork(): Result {
|
||||
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
||||
|
@ -60,7 +62,7 @@ class NSClientAddUpdateWorker(
|
|||
// new DB model
|
||||
val insulin = JsonHelper.safeGetDouble(json, "insulin")
|
||||
val carbs = JsonHelper.safeGetDouble(json, "carbs")
|
||||
val eventType = JsonHelper.safeGetString(json, "eventType")
|
||||
var eventType = JsonHelper.safeGetString(json, "eventType")
|
||||
if (eventType == null) {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Wrong treatment. Ignoring : $json")
|
||||
continue
|
||||
|
@ -138,7 +140,10 @@ class NSClientAddUpdateWorker(
|
|||
val ebJson = json.getJSONObject("extendedEmulated")
|
||||
ebJson.put("_id", json.getString("_id"))
|
||||
ebJson.put("isValid", json.getBoolean("isValid"))
|
||||
ebJson.put("mills", mills)
|
||||
json = ebJson
|
||||
eventType = JsonHelper.safeGetString(json, "eventType")
|
||||
virtualPumpPlugin.fakeDataDetected = true
|
||||
}
|
||||
when {
|
||||
insulin > 0 || carbs > 0 -> Any()
|
||||
|
|
|
@ -78,7 +78,7 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
it.isExtendedBolusCapable = true
|
||||
it.extendedBolusStep = 0.05
|
||||
it.extendedBolusDurationStep = 30.0
|
||||
it.extendedBolusMaxDuration = 8 * 60.toDouble()
|
||||
it.extendedBolusMaxDuration = 8 * 60.0
|
||||
it.isTempBasalCapable = true
|
||||
it.tempBasalStyle = PumpDescription.PERCENT or PumpDescription.ABSOLUTE
|
||||
it.maxTempPercent = 500
|
||||
|
@ -95,14 +95,6 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
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() {
|
||||
super.onStart()
|
||||
disposable += rxBus
|
||||
|
@ -125,7 +117,8 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
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?
|
||||
return PumpEnactResult(injector)
|
||||
|
@ -156,14 +149,9 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
return PumpEnactResult(injector).success(true).enacted(true)
|
||||
}
|
||||
|
||||
override fun isThisProfileSet(profile: Profile): Boolean {
|
||||
val running = pumpSync.expectedPumpState().profile
|
||||
return running?.isEqual(profile) ?: false
|
||||
}
|
||||
override fun isThisProfileSet(profile: Profile): Boolean = pumpSync.expectedPumpState().profile?.isEqual(profile) ?: false
|
||||
|
||||
override fun lastDataTime(): Long {
|
||||
return lastDataTime
|
||||
}
|
||||
override fun lastDataTime(): Long = lastDataTime
|
||||
|
||||
override val baseBasalRate: Double
|
||||
get() = profileFunction.getProfile()?.getBasal() ?: 0.0
|
||||
|
@ -373,25 +361,15 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
return pump
|
||||
}
|
||||
|
||||
override fun manufacturer(): ManufacturerType {
|
||||
return pumpDescription.pumpType.manufacturer ?: ManufacturerType.AndroidAPS
|
||||
}
|
||||
override fun manufacturer(): ManufacturerType = pumpDescription.pumpType.manufacturer ?: ManufacturerType.AndroidAPS
|
||||
|
||||
override fun model(): PumpType {
|
||||
return pumpDescription.pumpType
|
||||
}
|
||||
override fun model(): PumpType = pumpDescription.pumpType
|
||||
|
||||
override fun serialNumber(): String {
|
||||
return instanceId()
|
||||
}
|
||||
override fun serialNumber(): String = instanceId()
|
||||
|
||||
override fun shortStatus(veryShort: Boolean): String {
|
||||
return "Virtual Pump"
|
||||
}
|
||||
override fun shortStatus(veryShort: Boolean): String = "Virtual Pump"
|
||||
|
||||
override fun canHandleDST(): Boolean {
|
||||
return true
|
||||
}
|
||||
override fun canHandleDST(): Boolean = true
|
||||
|
||||
fun refreshConfiguration() {
|
||||
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) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -698,7 +698,6 @@
|
|||
<string name="no_action_selected">No action selected, nothing will happen</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="key_fromNSAreCommingFakedExtendedBoluses" translatable="false">fromNSAreCommingFakedExtendedBoluses</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="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
||||
|
|
|
@ -29,6 +29,7 @@ class SyncNsExtendedBolusTransaction(private val extendedBolus: ExtendedBolus) :
|
|||
}
|
||||
if (current.duration != extendedBolus.duration) {
|
||||
current.duration = extendedBolus.duration
|
||||
current.amount = extendedBolus.amount
|
||||
database.extendedBolusDao.updateExistingEntry(current)
|
||||
result.updatedDuration.add(current)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue