make automation profile switch based on last profile switch instead of profile store
This commit is contained in:
parent
dc90c6b140
commit
cf006790b9
2 changed files with 27 additions and 4 deletions
|
@ -117,9 +117,27 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createProfileSwitch(durationInMinutes: Int, percentage: Int, timeShiftInHours: Int) {
|
override fun createProfileSwitch(durationInMinutes: Int, percentage: Int, timeShiftInHours: Int) {
|
||||||
val profileStore = activePlugin.activeProfileSource.profile ?: return
|
val profile = repository.getPermanentProfileSwitch(dateUtil.now())
|
||||||
val profileName = activePlugin.activeProfileSource.profile?.getDefaultProfileName()
|
?: throw InvalidParameterSpecException("No active ProfileSwitch")
|
||||||
?: return
|
val ps = ProfileSwitch(
|
||||||
createProfileSwitch(profileStore, profileName, durationInMinutes, percentage, timeShiftInHours, dateUtil.now())
|
timestamp = dateUtil.now(),
|
||||||
|
basalBlocks = profile.basalBlocks,
|
||||||
|
isfBlocks = profile.isfBlocks,
|
||||||
|
icBlocks = profile.icBlocks,
|
||||||
|
targetBlocks = profile.targetBlocks,
|
||||||
|
glucoseUnit = profile.glucoseUnit,
|
||||||
|
profileName = profile.profileName,
|
||||||
|
timeshift = T.hours(timeShiftInHours.toLong()).msecs(),
|
||||||
|
percentage = percentage,
|
||||||
|
duration = T.mins(durationInMinutes.toLong()).msecs(),
|
||||||
|
insulinConfiguration = activePlugin.activeInsulin.insulinConfiguration
|
||||||
|
)
|
||||||
|
disposable += repository.runTransactionForResult(InsertOrUpdateProfileSwitch(ps))
|
||||||
|
.subscribe({ result ->
|
||||||
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted ProfileSwitch $it") }
|
||||||
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated ProfileSwitch $it") }
|
||||||
|
}, {
|
||||||
|
aapsLogger.error(LTag.DATABASE, "Error while saving ProfileSwitch", it)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -213,6 +213,11 @@ open class AppRepository @Inject internal constructor(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPermanentProfileSwitch(timestamp: Long): ProfileSwitch? =
|
||||||
|
database.profileSwitchDao.getPermanentProfileSwitchActiveAt(timestamp)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.blockingGet()
|
||||||
|
|
||||||
fun getAllProfileSwitches(): Single<List<ProfileSwitch>> =
|
fun getAllProfileSwitches(): Single<List<ProfileSwitch>> =
|
||||||
database.profileSwitchDao.getAllProfileSwitches()
|
database.profileSwitchDao.getAllProfileSwitches()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
Loading…
Reference in a new issue