fix double profile
This commit is contained in:
parent
17d5fcf07d
commit
f48dcc77e2
4 changed files with 69 additions and 60 deletions
|
@ -149,11 +149,14 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
swapAdapter()
|
swapAdapter()
|
||||||
disposable.add(rxBus
|
disposable += rxBus
|
||||||
.toObservable(EventProfileSwitchChanged::class.java)
|
.toObservable(EventProfileSwitchChanged::class.java)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||||
)
|
disposable += rxBus
|
||||||
|
.toObservable(EventEffectiveProfileSwitchChanged::class.java)
|
||||||
|
.observeOn(aapsSchedulers.main)
|
||||||
|
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
|
|
|
@ -2,8 +2,6 @@ package info.nightscout.androidaps.db
|
||||||
|
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.*
|
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.events.*
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
@ -34,56 +32,56 @@ class CompatDBHelper @Inject constructor(
|
||||||
*/
|
*/
|
||||||
var newestGlucoseValue: GlucoseValue? = null
|
var newestGlucoseValue: GlucoseValue? = null
|
||||||
it.filterIsInstance<GlucoseValue>().lastOrNull()?.let { gv ->
|
it.filterIsInstance<GlucoseValue>().lastOrNull()?.let { gv ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
|
||||||
rxBus.send(EventNewBG(gv))
|
rxBus.send(EventNewBG(gv))
|
||||||
newestGlucoseValue = gv
|
newestGlucoseValue = gv
|
||||||
}
|
}
|
||||||
it.filterIsInstance<GlucoseValue>().map { gv -> gv.timestamp }.minOrNull()?.let { timestamp ->
|
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))
|
rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<Carbs>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
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(EventTreatmentChange())
|
||||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<Bolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
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(EventTreatmentChange())
|
||||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<TemporaryBasal>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
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(EventTempBasalChange())
|
||||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<ExtendedBolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp ->
|
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(EventExtendedBolusChange())
|
||||||
rxBus.send(EventNewHistoryData(timestamp, false))
|
rxBus.send(EventNewHistoryData(timestamp, false))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let {
|
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let { tt ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTempTargetChange")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventTempTargetChange $tt")
|
||||||
rxBus.send(EventTempTargetChange())
|
rxBus.send(EventTempTargetChange())
|
||||||
}
|
}
|
||||||
it.filterIsInstance<TherapyEvent>().firstOrNull()?.let {
|
it.filterIsInstance<TherapyEvent>().firstOrNull()?.let { te ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventTherapyEventChange")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventTherapyEventChange $te")
|
||||||
rxBus.send(EventTherapyEventChange())
|
rxBus.send(EventTherapyEventChange())
|
||||||
}
|
}
|
||||||
it.filterIsInstance<Food>().firstOrNull()?.let {
|
it.filterIsInstance<Food>().firstOrNull()?.let { food ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged $food")
|
||||||
rxBus.send(EventFoodDatabaseChanged())
|
rxBus.send(EventFoodDatabaseChanged())
|
||||||
}
|
}
|
||||||
it.filterIsInstance<ProfileSwitch>().firstOrNull()?.let {
|
it.filterIsInstance<ProfileSwitch>().firstOrNull()?.let { ps ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged $ps")
|
||||||
rxBus.send(EventProfileSwitchChanged())
|
rxBus.send(EventProfileSwitchChanged())
|
||||||
}
|
}
|
||||||
it.filterIsInstance<EffectiveProfileSwitch>().firstOrNull()?.let { eps ->
|
it.filterIsInstance<EffectiveProfileSwitch>().firstOrNull()?.let { eps ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventEffectiveProfileSwitchChanged $eps")
|
||||||
rxBus.send(EventEffectiveProfileSwitchChanged(eps))
|
rxBus.send(EventEffectiveProfileSwitchChanged(eps))
|
||||||
}
|
}
|
||||||
it.filterIsInstance<OfflineEvent>().firstOrNull()?.let {
|
it.filterIsInstance<OfflineEvent>().firstOrNull()?.let { oe ->
|
||||||
aapsLogger.debug(LTag.DATABASE, "Firing EventOfflineChange")
|
aapsLogger.debug(LTag.DATABASE, "Firing EventOfflineChange $oe")
|
||||||
rxBus.send(EventOfflineChange())
|
rxBus.send(EventOfflineChange())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,15 +82,14 @@ class CommandQueueImplementation @Inject constructor(
|
||||||
if (config.NSCLIENT) { // Effective profileswitch should be synced over NS, do not create EffectiveProfileSwitch here
|
if (config.NSCLIENT) { // Effective profileswitch should be synced over NS, do not create EffectiveProfileSwitch here
|
||||||
return@subscribe
|
return@subscribe
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PROFILE, "onProfileSwitch")
|
aapsLogger.debug(LTag.PROFILE, "onEventProfileSwitchChanged")
|
||||||
profileFunction.getRequestedProfile()?.let {
|
profileFunction.getRequestedProfile()?.let {
|
||||||
val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil)
|
setProfile(ProfileSealed.PS(it), it.interfaceIDs.nightscoutId != null, object : Callback() {
|
||||||
setProfile(ProfileSealed.Pure(nonCustomized), it.interfaceIDs.nightscoutId != null, object : Callback() {
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ErrorHelperActivity.runAlarm(context, result.comment, rh.gs(R.string.failedupdatebasalprofile), R.raw.boluserror)
|
ErrorHelperActivity.runAlarm(context, result.comment, rh.gs(R.string.failedupdatebasalprofile), R.raw.boluserror)
|
||||||
} else {
|
} else if (result.enacted) {
|
||||||
repository.createEffectiveProfileSwitch(
|
val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil)
|
||||||
EffectiveProfileSwitch(
|
EffectiveProfileSwitch(
|
||||||
timestamp = dateUtil.now(),
|
timestamp = dateUtil.now(),
|
||||||
basalBlocks = nonCustomized.basalBlocks,
|
basalBlocks = nonCustomized.basalBlocks,
|
||||||
|
@ -105,8 +104,10 @@ class CommandQueueImplementation @Inject constructor(
|
||||||
originalDuration = it.duration,
|
originalDuration = it.duration,
|
||||||
originalEnd = it.end,
|
originalEnd = it.end,
|
||||||
insulinConfiguration = it.insulinConfiguration
|
insulinConfiguration = it.insulinConfiguration
|
||||||
)
|
).also { eps ->
|
||||||
)
|
repository.createEffectiveProfileSwitch(eps)
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Inserted EffectiveProfileSwitch $eps")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -195,9 +196,11 @@ class CommandQueueImplementation @Inject constructor(
|
||||||
|
|
||||||
override fun independentConnect(reason: String, callback: Callback?) {
|
override fun independentConnect(reason: String, callback: Callback?) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue")
|
aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue")
|
||||||
val tempCommandQueue = CommandQueueImplementation(injector, aapsLogger, rxBus, aapsSchedulers, rh,
|
val tempCommandQueue = CommandQueueImplementation(
|
||||||
|
injector, aapsLogger, rxBus, aapsSchedulers, rh,
|
||||||
constraintChecker, profileFunction, activePlugin, context, sp,
|
constraintChecker, profileFunction, activePlugin, context, sp,
|
||||||
buildHelper, dateUtil, repository, fabricPrivacy, config)
|
buildHelper, dateUtil, repository, fabricPrivacy, config
|
||||||
|
)
|
||||||
tempCommandQueue.readStatus(reason, callback)
|
tempCommandQueue.readStatus(reason, callback)
|
||||||
tempCommandQueue.disposable.clear()
|
tempCommandQueue.disposable.clear()
|
||||||
}
|
}
|
||||||
|
@ -398,6 +401,11 @@ class CommandQueueImplementation @Inject constructor(
|
||||||
|
|
||||||
// returns true if command is queued
|
// returns true if command is queued
|
||||||
override fun setProfile(profile: Profile, hasNsId: Boolean, callback: Callback?): Boolean {
|
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) {
|
if (isThisProfileSet(profile) && repository.getEffectiveProfileSwitchActiveAt(dateUtil.now()).blockingGet() is ValueWrapper.Existing) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "Correct profile already set")
|
aapsLogger.debug(LTag.PUMPQUEUE, "Correct profile already set")
|
||||||
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
|
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 (getIcTimeFromMidnight(seconds) != profile.getIcTimeFromMidnight(seconds)) return false
|
||||||
if (getTargetLowMgdlTimeFromMidnight(seconds) != profile.getTargetLowMgdlTimeFromMidnight(seconds)) return false
|
if (getTargetLowMgdlTimeFromMidnight(seconds) != profile.getTargetLowMgdlTimeFromMidnight(seconds)) return false
|
||||||
if (getTargetHighMgdlTimeFromMidnight(seconds) != profile.getTargetHighMgdlTimeFromMidnight(seconds)) return false
|
if (getTargetHighMgdlTimeFromMidnight(seconds) != profile.getTargetHighMgdlTimeFromMidnight(seconds)) return false
|
||||||
|
}
|
||||||
if (dia != profile.dia) return false
|
if (dia != profile.dia) return false
|
||||||
if ((profile is EPS) && profileName != profile.value.originalProfileName) return false // handle profile name change too
|
if ((profile is EPS) && profileName != profile.value.originalProfileName) return false // handle profile name change too
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue