diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt index 448e917ae9..d759844d87 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.kt @@ -566,11 +566,12 @@ open class CommandQueue @Inject constructor( return HtmlHelper.fromHtml(s) } - override fun isThisProfileSet(profile: Profile): Boolean { - val result = activePlugin.activePump.isThisProfileSet(profile) + override fun isThisProfileSet(requestedProfile: Profile): Boolean { + val runningProfile = profileFunction.getProfile() ?: return false + val result = activePlugin.activePump.isThisProfileSet(requestedProfile) && requestedProfile.isEqual(runningProfile) if (!result) { aapsLogger.debug(LTag.PUMPQUEUE, "Current profile: ${profileFunction.getProfile()}") - aapsLogger.debug(LTag.PUMPQUEUE, "New profile: $profile") + aapsLogger.debug(LTag.PUMPQUEUE, "New profile: $requestedProfile") } return result } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index 1b78360966..48f073e804 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -119,18 +119,18 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { private fun checkPump() { val pump = activePlugin.activePump val ps = profileFunction.getRequestedProfile() ?: return - val profile = ProfileSealed.PS(ps) + val requestedProfile = ProfileSealed.PS(ps) + val runningProfile = profileFunction.getProfile() val lastConnection = pump.lastDataTime() val isStatusOutdated = lastConnection + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis() - val isBasalOutdated = abs(profile.getBasal() - pump.baseBasalRate) > pump.pumpDescription.basalStep + val isBasalOutdated = abs(requestedProfile.getBasal() - pump.baseBasalRate) > pump.pumpDescription.basalStep aapsLogger.debug(LTag.CORE, "Last connection: " + dateUtil.dateAndTimeString(lastConnection)) // sometimes keep alive broadcast stops // as as workaround test if readStatus was requested before an alarm is generated if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) { localAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loopPlugin.isDisconnected) } - if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE) - || profileFunction.getProfile() == null) { + if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile)) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) { rxBus.send(EventProfileSwitchChanged()) } else if (isStatusOutdated && !pump.isBusy()) { lastReadStatus = System.currentTimeMillis()