fix updating non basal profile changes

This commit is contained in:
Milos Kozak 2021-05-25 21:19:18 +02:00
parent 3ed45fdd11
commit 3d1b7e8ded
2 changed files with 8 additions and 7 deletions

View file

@ -566,11 +566,12 @@ open class CommandQueue @Inject constructor(
return HtmlHelper.fromHtml(s) return HtmlHelper.fromHtml(s)
} }
override fun isThisProfileSet(profile: Profile): Boolean { override fun isThisProfileSet(requestedProfile: Profile): Boolean {
val result = activePlugin.activePump.isThisProfileSet(profile) val runningProfile = profileFunction.getProfile() ?: return false
val result = activePlugin.activePump.isThisProfileSet(requestedProfile) && requestedProfile.isEqual(runningProfile)
if (!result) { if (!result) {
aapsLogger.debug(LTag.PUMPQUEUE, "Current profile: ${profileFunction.getProfile()}") aapsLogger.debug(LTag.PUMPQUEUE, "Current profile: ${profileFunction.getProfile()}")
aapsLogger.debug(LTag.PUMPQUEUE, "New profile: $profile") aapsLogger.debug(LTag.PUMPQUEUE, "New profile: $requestedProfile")
} }
return result return result
} }

View file

@ -119,18 +119,18 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
private fun checkPump() { private fun checkPump() {
val pump = activePlugin.activePump val pump = activePlugin.activePump
val ps = profileFunction.getRequestedProfile() ?: return val ps = profileFunction.getRequestedProfile() ?: return
val profile = ProfileSealed.PS(ps) val requestedProfile = ProfileSealed.PS(ps)
val runningProfile = profileFunction.getProfile()
val lastConnection = pump.lastDataTime() val lastConnection = pump.lastDataTime()
val isStatusOutdated = lastConnection + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis() 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)) aapsLogger.debug(LTag.CORE, "Last connection: " + dateUtil.dateAndTimeString(lastConnection))
// sometimes keep alive broadcast stops // sometimes keep alive broadcast stops
// as as workaround test if readStatus was requested before an alarm is generated // as as workaround test if readStatus was requested before an alarm is generated
if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) { if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) {
localAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loopPlugin.isDisconnected) localAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loopPlugin.isDisconnected)
} }
if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE) if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile)) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) {
|| profileFunction.getProfile() == null) {
rxBus.send(EventProfileSwitchChanged()) rxBus.send(EventProfileSwitchChanged())
} else if (isStatusOutdated && !pump.isBusy()) { } else if (isStatusOutdated && !pump.isBusy()) {
lastReadStatus = System.currentTimeMillis() lastReadStatus = System.currentTimeMillis()