fix overlapping profile switches of the same value, fix storing profiles from NS

This commit is contained in:
Milos Kozak 2023-05-13 23:18:06 +02:00
parent 016cf9dada
commit 01bb554651
6 changed files with 8 additions and 15 deletions

View file

@ -191,7 +191,7 @@ class KeepAliveWorker(
} }
if (loop.isDisconnected) { if (loop.isDisconnected) {
// do nothing if pump is disconnected // do nothing if pump is disconnected
} else if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile)) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) { } else if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile) || (runningProfile is ProfileSealed.EPS && runningProfile.value.originalEnd < dateUtil.now())) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) {
rxBus.send(EventProfileSwitchChanged()) rxBus.send(EventProfileSwitchChanged())
} else if (isStatusOutdated && !pump.isBusy()) { } else if (isStatusOutdated && !pump.isBusy()) {
lastReadStatus = now lastReadStatus = now

View file

@ -25,7 +25,6 @@ interface CommandQueue {
fun extendedBolus(insulin: Double, durationInMinutes: Int, callback: Callback?): Boolean fun extendedBolus(insulin: Double, durationInMinutes: Int, callback: Callback?): Boolean
fun cancelTempBasal(enforceNew: Boolean, callback: Callback?): Boolean fun cancelTempBasal(enforceNew: Boolean, callback: Callback?): Boolean
fun cancelExtended(callback: Callback?): Boolean fun cancelExtended(callback: Callback?): Boolean
fun setProfile(profile: Profile, hasNsId: Boolean, callback: Callback?): Boolean
fun readStatus(reason: String, callback: Callback?): Boolean fun readStatus(reason: String, callback: Callback?): Boolean
fun statusInQueue(): Boolean fun statusInQueue(): Boolean
fun loadHistory(type: Byte, callback: Callback?): Boolean fun loadHistory(type: Byte, callback: Callback?): Boolean

View file

@ -71,7 +71,7 @@ class ProfileFunctionImpl @Inject constructor(
override fun getProfileNameWithRemainingTime(): String = override fun getProfileNameWithRemainingTime(): String =
getProfileName(System.currentTimeMillis(), customized = true, showRemainingTime = true) getProfileName(System.currentTimeMillis(), customized = true, showRemainingTime = true)
fun getProfileName(time: Long, customized: Boolean, showRemainingTime: Boolean): String { private fun getProfileName(time: Long, customized: Boolean, showRemainingTime: Boolean): String {
var profileName = rh.gs(info.nightscout.core.ui.R.string.no_profile_set) var profileName = rh.gs(info.nightscout.core.ui.R.string.no_profile_set)
val profileSwitch = repository.getEffectiveProfileSwitchActiveAt(time).blockingGet() val profileSwitch = repository.getEffectiveProfileSwitchActiveAt(time).blockingGet()

View file

@ -113,12 +113,13 @@ class CommandQueueImplementation @Inject constructor(
return@subscribe return@subscribe
} }
aapsLogger.debug(LTag.PROFILE, "onEventProfileSwitchChanged") aapsLogger.debug(LTag.PROFILE, "onEventProfileSwitchChanged")
val effective = repository.getEffectiveProfileSwitchActiveAt(dateUtil.now()).blockingGet()
profileFunction.getRequestedProfile()?.let { profileFunction.getRequestedProfile()?.let {
setProfile(ProfileSealed.PS(it), it.interfaceIDs.nightscoutId != null, object : Callback() { setProfile(ProfileSealed.PS(it), it.interfaceIDs.nightscoutId != null, object : Callback() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.failed_update_basal_profile), info.nightscout.core.ui.R.raw.boluserror) uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.failed_update_basal_profile), info.nightscout.core.ui.R.raw.boluserror)
} else if (result.enacted) { } else if (result.enacted || effective is ValueWrapper.Existing && effective.value.originalEnd < dateUtil.now()) {
val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil) val nonCustomized = ProfileSealed.PS(it).convertToNonCustomizedProfile(dateUtil)
EffectiveProfileSwitch( EffectiveProfileSwitch(
timestamp = dateUtil.now(), timestamp = dateUtil.now(),
@ -421,7 +422,7 @@ 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 { fun setProfile(profile: ProfileSealed.PS, hasNsId: Boolean, callback: Callback?): Boolean {
if (isRunning(CommandType.BASAL_PROFILE)) { if (isRunning(CommandType.BASAL_PROFILE)) {
aapsLogger.debug(LTag.PUMPQUEUE, "Command is already executed") aapsLogger.debug(LTag.PUMPQUEUE, "Command is already executed")
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run() callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()

View file

@ -841,11 +841,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L)
info.nightscout.core.ui.R.attr.ribbonWarningColor info.nightscout.core.ui.R.attr.ribbonWarningColor
else info.nightscout.core.ui.R.attr.ribbonDefaultColor else info.nightscout.core.ui.R.attr.ribbonDefaultColor
} else if (it is ProfileSealed.PS) { } else info.nightscout.core.ui.R.attr.ribbonDefaultColor
info.nightscout.core.ui.R.attr.ribbonDefaultColor
} else {
info.nightscout.core.ui.R.attr.ribbonDefaultColor
}
} ?: info.nightscout.core.ui.R.attr.ribbonCriticalColor } ?: info.nightscout.core.ui.R.attr.ribbonCriticalColor
val profileTextColor = profile?.let { val profileTextColor = profile?.let {
@ -853,11 +849,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L)
info.nightscout.core.ui.R.attr.ribbonTextWarningColor info.nightscout.core.ui.R.attr.ribbonTextWarningColor
else info.nightscout.core.ui.R.attr.ribbonTextDefaultColor else info.nightscout.core.ui.R.attr.ribbonTextDefaultColor
} else if (it is ProfileSealed.PS) { } else info.nightscout.core.ui.R.attr.ribbonTextDefaultColor
info.nightscout.core.ui.R.attr.ribbonTextDefaultColor
} else {
info.nightscout.core.ui.R.attr.ribbonTextDefaultColor
}
} ?: info.nightscout.core.ui.R.attr.ribbonTextDefaultColor } ?: info.nightscout.core.ui.R.attr.ribbonTextDefaultColor
setRibbon(binding.activeProfile, profileTextColor, profileBackgroundColor, profileFunction.getProfileNameWithRemainingTime()) setRibbon(binding.activeProfile, profileTextColor, profileBackgroundColor, profileFunction.getProfileNameWithRemainingTime())
} }

View file

@ -255,6 +255,7 @@ class ProfilePlugin @Inject constructor(
isEdited = false isEdited = false
createAndStoreConvertedProfile() createAndStoreConvertedProfile()
aapsLogger.debug(LTag.PROFILE, "Accepted ${profiles.size} profiles") aapsLogger.debug(LTag.PROFILE, "Accepted ${profiles.size} profiles")
storeSettings()
rxBus.send(EventLocalProfileChanged()) rxBus.send(EventLocalProfileChanged())
} else } else
aapsLogger.debug(LTag.PROFILE, "ProfileStore not accepted") aapsLogger.debug(LTag.PROFILE, "ProfileStore not accepted")