fix double profile
This commit is contained in:
parent
17d5fcf07d
commit
f48dcc77e2
|
@ -149,11 +149,14 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
swapAdapter()
|
||||
disposable.add(rxBus
|
||||
disposable += rxBus
|
||||
.toObservable(EventProfileSwitchChanged::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
)
|
||||
disposable += rxBus
|
||||
.toObservable(EventEffectiveProfileSwitchChanged::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
|
|
@ -2,8 +2,6 @@ package info.nightscout.androidaps.db
|
|||
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.*
|
||||
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
||||
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
||||
import info.nightscout.androidaps.events.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -34,56 +32,56 @@ class CompatDBHelper @Inject constructor(
|
|||
*/
|
||||
var newestGlucoseValue: GlucoseValue? = null
|
||||
it.filterIsInstance<GlucoseValue>().lastOrNull()?.let { gv ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
|
||||
rxBus.send(EventNewBG(gv))
|
||||
newestGlucoseValue = gv
|
||||
}
|
||||
it.filterIsInstance<GlucoseValue>().map { gv -> gv.timestamp }.minOrNull()?.let { timestamp ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $newestGlucoseValue")
|
||||
rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue))
|
||||
}
|
||||
it.filterIsInstance<Carbs>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp")
|
||||
rxBus.send(EventTreatmentChange())
|
||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||
}
|
||||
it.filterIsInstance<Bolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp")
|
||||
rxBus.send(EventTreatmentChange())
|
||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||
}
|
||||
it.filterIsInstance<TemporaryBasal>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange $timestamp")
|
||||
rxBus.send(EventTempBasalChange())
|
||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||
}
|
||||
it.filterIsInstance<ExtendedBolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange $timestamp")
|
||||
rxBus.send(EventExtendedBolusChange())
|
||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||
}
|
||||
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTempTargetChange")
|
||||
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let { tt ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTempTargetChange $tt")
|
||||
rxBus.send(EventTempTargetChange())
|
||||
}
|
||||
it.filterIsInstance<TherapyEvent>().firstOrNull()?.let {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTherapyEventChange")
|
||||
it.filterIsInstance<TherapyEvent>().firstOrNull()?.let { te ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTherapyEventChange $te")
|
||||
rxBus.send(EventTherapyEventChange())
|
||||
}
|
||||
it.filterIsInstance<Food>().firstOrNull()?.let {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged")
|
||||
it.filterIsInstance<Food>().firstOrNull()?.let { food ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged $food")
|
||||
rxBus.send(EventFoodDatabaseChanged())
|
||||
}
|
||||
it.filterIsInstance<ProfileSwitch>().firstOrNull()?.let {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged")
|
||||
it.filterIsInstance<ProfileSwitch>().firstOrNull()?.let { ps ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged $ps")
|
||||
rxBus.send(EventProfileSwitchChanged())
|
||||
}
|
||||
it.filterIsInstance<EffectiveProfileSwitch>().firstOrNull()?.let { eps ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged")
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventEffectiveProfileSwitchChanged $eps")
|
||||
rxBus.send(EventEffectiveProfileSwitchChanged(eps))
|
||||
}
|
||||
it.filterIsInstance<OfflineEvent>().firstOrNull()?.let {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventOfflineChange")
|
||||
it.filterIsInstance<OfflineEvent>().firstOrNull()?.let { oe ->
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventOfflineChange $oe")
|
||||
rxBus.send(EventOfflineChange())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,39 +79,40 @@ class CommandQueueImplementation @Inject constructor(
|
|||
.toObservable(EventProfileSwitchChanged::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.subscribe({
|
||||
if (config.NSCLIENT) { // Effective profileswitch should be synced over NS, do not create EffectiveProfileSwitch here
|
||||
return@subscribe
|
||||
}
|
||||
aapsLogger.debug(LTag.PROFILE, "onProfileSwitch")
|
||||
profileFunction.getRequestedProfile()?.let {
|
||||
val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil)
|
||||
setProfile(ProfileSealed.Pure(nonCustomized), it.interfaceIDs.nightscoutId != null, object : Callback() {
|
||||
override fun run() {
|
||||
if (!result.success) {
|
||||
ErrorHelperActivity.runAlarm(context, result.comment, rh.gs(R.string.failedupdatebasalprofile), R.raw.boluserror)
|
||||
} else {
|
||||
repository.createEffectiveProfileSwitch(
|
||||
EffectiveProfileSwitch(
|
||||
timestamp = dateUtil.now(),
|
||||
basalBlocks = nonCustomized.basalBlocks,
|
||||
isfBlocks = nonCustomized.isfBlocks,
|
||||
icBlocks = nonCustomized.icBlocks,
|
||||
targetBlocks = nonCustomized.targetBlocks,
|
||||
glucoseUnit = if (it.glucoseUnit == ProfileSwitch.GlucoseUnit.MGDL) EffectiveProfileSwitch.GlucoseUnit.MGDL else EffectiveProfileSwitch.GlucoseUnit.MMOL,
|
||||
originalProfileName = it.profileName,
|
||||
originalCustomizedName = it.getCustomizedName(),
|
||||
originalTimeshift = it.timeshift,
|
||||
originalPercentage = it.percentage,
|
||||
originalDuration = it.duration,
|
||||
originalEnd = it.end,
|
||||
insulinConfiguration = it.insulinConfiguration
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}, fabricPrivacy::logException)
|
||||
if (config.NSCLIENT) { // Effective profileswitch should be synced over NS, do not create EffectiveProfileSwitch here
|
||||
return@subscribe
|
||||
}
|
||||
aapsLogger.debug(LTag.PROFILE, "onEventProfileSwitchChanged")
|
||||
profileFunction.getRequestedProfile()?.let {
|
||||
setProfile(ProfileSealed.PS(it), it.interfaceIDs.nightscoutId != null, object : Callback() {
|
||||
override fun run() {
|
||||
if (!result.success) {
|
||||
ErrorHelperActivity.runAlarm(context, result.comment, rh.gs(R.string.failedupdatebasalprofile), R.raw.boluserror)
|
||||
} else if (result.enacted) {
|
||||
val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil)
|
||||
EffectiveProfileSwitch(
|
||||
timestamp = dateUtil.now(),
|
||||
basalBlocks = nonCustomized.basalBlocks,
|
||||
isfBlocks = nonCustomized.isfBlocks,
|
||||
icBlocks = nonCustomized.icBlocks,
|
||||
targetBlocks = nonCustomized.targetBlocks,
|
||||
glucoseUnit = if (it.glucoseUnit == ProfileSwitch.GlucoseUnit.MGDL) EffectiveProfileSwitch.GlucoseUnit.MGDL else EffectiveProfileSwitch.GlucoseUnit.MMOL,
|
||||
originalProfileName = it.profileName,
|
||||
originalCustomizedName = it.getCustomizedName(),
|
||||
originalTimeshift = it.timeshift,
|
||||
originalPercentage = it.percentage,
|
||||
originalDuration = it.duration,
|
||||
originalEnd = it.end,
|
||||
insulinConfiguration = it.insulinConfiguration
|
||||
).also { eps ->
|
||||
repository.createEffectiveProfileSwitch(eps)
|
||||
aapsLogger.debug(LTag.DATABASE, "Inserted EffectiveProfileSwitch $eps")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
private fun executingNowError(): PumpEnactResult =
|
||||
|
@ -195,9 +196,11 @@ class CommandQueueImplementation @Inject constructor(
|
|||
|
||||
override fun independentConnect(reason: String, callback: Callback?) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue")
|
||||
val tempCommandQueue = CommandQueueImplementation(injector, aapsLogger, rxBus, aapsSchedulers, rh,
|
||||
constraintChecker, profileFunction, activePlugin, context, sp,
|
||||
buildHelper, dateUtil, repository, fabricPrivacy, config)
|
||||
val tempCommandQueue = CommandQueueImplementation(
|
||||
injector, aapsLogger, rxBus, aapsSchedulers, rh,
|
||||
constraintChecker, profileFunction, activePlugin, context, sp,
|
||||
buildHelper, dateUtil, repository, fabricPrivacy, config
|
||||
)
|
||||
tempCommandQueue.readStatus(reason, callback)
|
||||
tempCommandQueue.disposable.clear()
|
||||
}
|
||||
|
@ -222,7 +225,7 @@ class CommandQueueImplementation @Inject constructor(
|
|||
// If not, it's not necessary add command to the queue and initiate connection
|
||||
// Assuming carbs in the future and carbs with duration are NOT stores anyway
|
||||
|
||||
var carbsRunnable = Runnable { }
|
||||
var carbsRunnable = Runnable { }
|
||||
val originalCarbs = detailedBolusInfo.carbs
|
||||
if ((detailedBolusInfo.carbs > 0) &&
|
||||
(!activePlugin.activePump.pumpDescription.storesCarbInfo ||
|
||||
|
@ -398,6 +401,11 @@ class CommandQueueImplementation @Inject constructor(
|
|||
|
||||
// returns true if command is queued
|
||||
override fun setProfile(profile: Profile, hasNsId: Boolean, callback: Callback?): Boolean {
|
||||
if (isRunning(CommandType.BASAL_PROFILE)) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Command is already executed")
|
||||
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
|
||||
return false
|
||||
}
|
||||
if (isThisProfileSet(profile) && repository.getEffectiveProfileSwitchActiveAt(dateUtil.now()).blockingGet() is ValueWrapper.Existing) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Correct profile already set")
|
||||
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
|
||||
|
|
|
@ -211,9 +211,9 @@ sealed class ProfileSealed(
|
|||
if (getIcTimeFromMidnight(seconds) != profile.getIcTimeFromMidnight(seconds)) return false
|
||||
if (getTargetLowMgdlTimeFromMidnight(seconds) != profile.getTargetLowMgdlTimeFromMidnight(seconds)) return false
|
||||
if (getTargetHighMgdlTimeFromMidnight(seconds) != profile.getTargetHighMgdlTimeFromMidnight(seconds)) return false
|
||||
if (dia != profile.dia) return false
|
||||
if ((profile is EPS) && profileName != profile.value.originalProfileName) return false // handle profile name change too
|
||||
}
|
||||
if (dia != profile.dia) return false
|
||||
if ((profile is EPS) && profileName != profile.value.originalProfileName) return false // handle profile name change too
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue