Merge branch 'avereha/merge' into avereha/conn
This commit is contained in:
commit
ca0f7482f3
17 changed files with 84 additions and 33 deletions
|
@ -134,7 +134,12 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
|
||||
// Ask when switching to physical pump plugin
|
||||
fun switchAllowed(changedPlugin: PluginBase, newState: Boolean, activity: FragmentActivity?, type: PluginType) {
|
||||
if (changedPlugin.getType() == PluginType.PUMP && changedPlugin.name != resourceHelper.gs(R.string.virtualpump)) confirmPumpPluginActivation(changedPlugin, newState, activity, type) else performPluginSwitch(changedPlugin, newState, type)
|
||||
if (changedPlugin.getType() == PluginType.PUMP && changedPlugin.name != resourceHelper.gs(R.string.virtualpump))
|
||||
confirmPumpPluginActivation(changedPlugin, newState, activity, type)
|
||||
else if (changedPlugin.getType() == PluginType.PUMP) {
|
||||
performPluginSwitch(changedPlugin, newState, type)
|
||||
pumpSync.connectNewPump()
|
||||
} else performPluginSwitch(changedPlugin, newState, type)
|
||||
}
|
||||
|
||||
private fun confirmPumpPluginActivation(changedPlugin: PluginBase, newState: Boolean, activity: FragmentActivity?, type: PluginType) {
|
||||
|
|
|
@ -117,9 +117,27 @@ class ProfileFunctionImplementation @Inject constructor(
|
|||
}
|
||||
|
||||
override fun createProfileSwitch(durationInMinutes: Int, percentage: Int, timeShiftInHours: Int) {
|
||||
val profileStore = activePlugin.activeProfileSource.profile ?: return
|
||||
val profileName = activePlugin.activeProfileSource.profile?.getDefaultProfileName()
|
||||
?: return
|
||||
createProfileSwitch(profileStore, profileName, durationInMinutes, percentage, timeShiftInHours, dateUtil.now())
|
||||
val profile = repository.getPermanentProfileSwitch(dateUtil.now())
|
||||
?: throw InvalidParameterSpecException("No active ProfileSwitch")
|
||||
val ps = ProfileSwitch(
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
|||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.mozilla.javascript.tools.jsc.Main
|
||||
import javax.inject.Inject
|
||||
|
||||
class ErrorDialog : DaggerDialogFragment() {
|
||||
|
|
|
@ -68,7 +68,7 @@ class PumpSyncImplementation @Inject constructor(
|
|||
return true
|
||||
}
|
||||
|
||||
if (type.description != storedType || serialNumber != storedSerial)
|
||||
if ((type.description != storedType || serialNumber != storedSerial) && timestamp >= storedTimestamp)
|
||||
rxBus.send(EventNewNotification(Notification(Notification.WRONG_PUMP_DATA, resourceHelper.gs(R.string.wrong_pump_data), Notification.URGENT)))
|
||||
aapsLogger.error(LTag.PUMP, "Ignoring pump history record Allowed: ${dateUtil.dateAndTimeAndSecondsString(storedTimestamp)} $storedType $storedSerial Received: $timestamp ${dateUtil.dateAndTimeAndSecondsString(timestamp)} ${type.description} $serialNumber")
|
||||
return false
|
||||
|
|
|
@ -213,6 +213,11 @@ open class AppRepository @Inject internal constructor(
|
|||
return null
|
||||
}
|
||||
|
||||
fun getPermanentProfileSwitch(timestamp: Long): ProfileSwitch? =
|
||||
database.profileSwitchDao.getPermanentProfileSwitchActiveAt(timestamp)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.blockingGet()
|
||||
|
||||
fun getAllProfileSwitches(): Single<List<ProfileSwitch>> =
|
||||
database.profileSwitchDao.getAllProfileSwitches()
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
|
|
@ -6,7 +6,9 @@ class UpdateNsIdBolusCalculatorResultTransaction(val bolusCalculatorResult: Bolu
|
|||
|
||||
override fun run() {
|
||||
val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId)
|
||||
database.bolusCalculatorResultDao.updateExistingEntry(bolusCalculatorResult)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolusCalculatorResult.interfaceIDs.nightscoutId
|
||||
database.bolusCalculatorResultDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdBolusTransaction(val bolus: Bolus) : Transaction<Unit>() {
|
|||
|
||||
override fun run() {
|
||||
val current = database.bolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId)
|
||||
database.bolusDao.updateExistingEntry(bolus)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.bolusDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdCarbsTransaction(val carbs: Carbs) : Transaction<Unit>() {
|
|||
|
||||
override fun run() {
|
||||
val current = database.carbsDao.findById(carbs.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId)
|
||||
database.carbsDao.updateExistingEntry(carbs)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = carbs.interfaceIDs.nightscoutId
|
||||
database.carbsDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdDeviceStatusTransaction(val deviceStatus: DeviceStatus) : Transa
|
|||
|
||||
override fun run() {
|
||||
val current = database.deviceStatusDao.findById(deviceStatus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId)
|
||||
database.deviceStatusDao.update(deviceStatus)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = deviceStatus.interfaceIDs.nightscoutId
|
||||
database.deviceStatusDao.update(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdExtendedBolusTransaction(val bolus: ExtendedBolus) : Transaction
|
|||
|
||||
override fun run() {
|
||||
val current = database.extendedBolusDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId)
|
||||
database.extendedBolusDao.updateExistingEntry(bolus)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||
database.extendedBolusDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdFoodTransaction(val food: Food) : Transaction<Unit>() {
|
|||
|
||||
override fun run() {
|
||||
val current = database.foodDao.findById(food.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId)
|
||||
database.foodDao.updateExistingEntry(food)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = food.interfaceIDs.nightscoutId
|
||||
database.foodDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdGlucoseValueTransaction(val glucoseValue: GlucoseValue) : Transa
|
|||
|
||||
override fun run() {
|
||||
val current = database.glucoseValueDao.findById(glucoseValue.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId)
|
||||
database.glucoseValueDao.updateExistingEntry(glucoseValue)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = glucoseValue.interfaceIDs.nightscoutId
|
||||
database.glucoseValueDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdOfflineEventTransaction(val offlineEvent: OfflineEvent) : Transa
|
|||
|
||||
override fun run() {
|
||||
val current = database.offlineEventDao.findById(offlineEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId)
|
||||
database.offlineEventDao.updateExistingEntry(offlineEvent)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = offlineEvent.interfaceIDs.nightscoutId
|
||||
database.offlineEventDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdProfileSwitchTransaction(val profileSwitch: ProfileSwitch) : Tra
|
|||
|
||||
override fun run() {
|
||||
val current = database.profileSwitchDao.findById(profileSwitch.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId)
|
||||
database.profileSwitchDao.updateExistingEntry(profileSwitch)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = profileSwitch.interfaceIDs.nightscoutId
|
||||
database.profileSwitchDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,13 @@ package info.nightscout.androidaps.database.transactions
|
|||
|
||||
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
||||
|
||||
class UpdateNsIdTemporaryBasalTransaction(val bolus: TemporaryBasal) : Transaction<Unit>() {
|
||||
class UpdateNsIdTemporaryBasalTransaction(val temporaryBasal: TemporaryBasal) : Transaction<Unit>() {
|
||||
|
||||
override fun run() {
|
||||
val current = database.temporaryBasalDao.findById(bolus.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId)
|
||||
database.temporaryBasalDao.updateExistingEntry(bolus)
|
||||
val current = database.temporaryBasalDao.findById(temporaryBasal.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryBasal.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryBasal.interfaceIDs.nightscoutId
|
||||
database.temporaryBasalDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdTemporaryTargetTransaction(val temporaryTarget: TemporaryTarget)
|
|||
|
||||
override fun run() {
|
||||
val current = database.temporaryTargetDao.findById(temporaryTarget.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId)
|
||||
database.temporaryTargetDao.updateExistingEntry(temporaryTarget)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = temporaryTarget.interfaceIDs.nightscoutId
|
||||
database.temporaryTargetDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,9 @@ class UpdateNsIdTherapyEventTransaction(val therapyEvent: TherapyEvent) : Transa
|
|||
|
||||
override fun run() {
|
||||
val current = database.therapyEventDao.findById(therapyEvent.id)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId)
|
||||
database.therapyEventDao.updateExistingEntry(therapyEvent)
|
||||
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId) {
|
||||
current.interfaceIDs.nightscoutId = therapyEvent.interfaceIDs.nightscoutId
|
||||
database.therapyEventDao.updateExistingEntry(current)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue