Merge branch 'avereha/merge' into avereha/conn

This commit is contained in:
Andrei Vereha 2021-06-27 11:34:30 +02:00
commit ca0f7482f3
17 changed files with 84 additions and 33 deletions

View file

@ -134,7 +134,12 @@ class ConfigBuilderPlugin @Inject constructor(
// Ask when switching to physical pump plugin // Ask when switching to physical pump plugin
fun switchAllowed(changedPlugin: PluginBase, newState: Boolean, activity: FragmentActivity?, type: PluginType) { 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) { private fun confirmPumpPluginActivation(changedPlugin: PluginBase, newState: Boolean, activity: FragmentActivity?, type: PluginType) {

View file

@ -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)
})
} }
} }

View file

@ -17,7 +17,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import org.mozilla.javascript.tools.jsc.Main
import javax.inject.Inject import javax.inject.Inject
class ErrorDialog : DaggerDialogFragment() { class ErrorDialog : DaggerDialogFragment() {

View file

@ -68,7 +68,7 @@ class PumpSyncImplementation @Inject constructor(
return true 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))) 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") aapsLogger.error(LTag.PUMP, "Ignoring pump history record Allowed: ${dateUtil.dateAndTimeAndSecondsString(storedTimestamp)} $storedType $storedSerial Received: $timestamp ${dateUtil.dateAndTimeAndSecondsString(timestamp)} ${type.description} $serialNumber")
return false return false

View file

@ -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())

View file

@ -6,7 +6,9 @@ class UpdateNsIdBolusCalculatorResultTransaction(val bolusCalculatorResult: Bolu
override fun run() { override fun run() {
val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id) val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id)
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId) {
database.bolusCalculatorResultDao.updateExistingEntry(bolusCalculatorResult) current.interfaceIDs.nightscoutId = bolusCalculatorResult.interfaceIDs.nightscoutId
database.bolusCalculatorResultDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdBolusTransaction(val bolus: Bolus) : Transaction<Unit>() {
override fun run() { override fun run() {
val current = database.bolusDao.findById(bolus.id) val current = database.bolusDao.findById(bolus.id)
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
database.bolusDao.updateExistingEntry(bolus) current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
database.bolusDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdCarbsTransaction(val carbs: Carbs) : Transaction<Unit>() {
override fun run() { override fun run() {
val current = database.carbsDao.findById(carbs.id) val current = database.carbsDao.findById(carbs.id)
if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId) {
database.carbsDao.updateExistingEntry(carbs) current.interfaceIDs.nightscoutId = carbs.interfaceIDs.nightscoutId
database.carbsDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdDeviceStatusTransaction(val deviceStatus: DeviceStatus) : Transa
override fun run() { override fun run() {
val current = database.deviceStatusDao.findById(deviceStatus.id) val current = database.deviceStatusDao.findById(deviceStatus.id)
if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != deviceStatus.interfaceIDs.nightscoutId) {
database.deviceStatusDao.update(deviceStatus) current.interfaceIDs.nightscoutId = deviceStatus.interfaceIDs.nightscoutId
database.deviceStatusDao.update(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdExtendedBolusTransaction(val bolus: ExtendedBolus) : Transaction
override fun run() { override fun run() {
val current = database.extendedBolusDao.findById(bolus.id) val current = database.extendedBolusDao.findById(bolus.id)
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) {
database.extendedBolusDao.updateExistingEntry(bolus) current.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
database.extendedBolusDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdFoodTransaction(val food: Food) : Transaction<Unit>() {
override fun run() { override fun run() {
val current = database.foodDao.findById(food.id) val current = database.foodDao.findById(food.id)
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId) {
database.foodDao.updateExistingEntry(food) current.interfaceIDs.nightscoutId = food.interfaceIDs.nightscoutId
database.foodDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdGlucoseValueTransaction(val glucoseValue: GlucoseValue) : Transa
override fun run() { override fun run() {
val current = database.glucoseValueDao.findById(glucoseValue.id) val current = database.glucoseValueDao.findById(glucoseValue.id)
if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != glucoseValue.interfaceIDs.nightscoutId) {
database.glucoseValueDao.updateExistingEntry(glucoseValue) current.interfaceIDs.nightscoutId = glucoseValue.interfaceIDs.nightscoutId
database.glucoseValueDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdOfflineEventTransaction(val offlineEvent: OfflineEvent) : Transa
override fun run() { override fun run() {
val current = database.offlineEventDao.findById(offlineEvent.id) val current = database.offlineEventDao.findById(offlineEvent.id)
if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != offlineEvent.interfaceIDs.nightscoutId) {
database.offlineEventDao.updateExistingEntry(offlineEvent) current.interfaceIDs.nightscoutId = offlineEvent.interfaceIDs.nightscoutId
database.offlineEventDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdProfileSwitchTransaction(val profileSwitch: ProfileSwitch) : Tra
override fun run() { override fun run() {
val current = database.profileSwitchDao.findById(profileSwitch.id) val current = database.profileSwitchDao.findById(profileSwitch.id)
if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != profileSwitch.interfaceIDs.nightscoutId) {
database.profileSwitchDao.updateExistingEntry(profileSwitch) current.interfaceIDs.nightscoutId = profileSwitch.interfaceIDs.nightscoutId
database.profileSwitchDao.updateExistingEntry(current)
}
} }
} }

View file

@ -2,11 +2,13 @@ package info.nightscout.androidaps.database.transactions
import info.nightscout.androidaps.database.entities.TemporaryBasal import info.nightscout.androidaps.database.entities.TemporaryBasal
class UpdateNsIdTemporaryBasalTransaction(val bolus: TemporaryBasal) : Transaction<Unit>() { class UpdateNsIdTemporaryBasalTransaction(val temporaryBasal: TemporaryBasal) : Transaction<Unit>() {
override fun run() { override fun run() {
val current = database.temporaryBasalDao.findById(bolus.id) val current = database.temporaryBasalDao.findById(temporaryBasal.id)
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != temporaryBasal.interfaceIDs.nightscoutId) {
database.temporaryBasalDao.updateExistingEntry(bolus) current.interfaceIDs.nightscoutId = temporaryBasal.interfaceIDs.nightscoutId
database.temporaryBasalDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdTemporaryTargetTransaction(val temporaryTarget: TemporaryTarget)
override fun run() { override fun run() {
val current = database.temporaryTargetDao.findById(temporaryTarget.id) val current = database.temporaryTargetDao.findById(temporaryTarget.id)
if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != temporaryTarget.interfaceIDs.nightscoutId) {
database.temporaryTargetDao.updateExistingEntry(temporaryTarget) current.interfaceIDs.nightscoutId = temporaryTarget.interfaceIDs.nightscoutId
database.temporaryTargetDao.updateExistingEntry(current)
}
} }
} }

View file

@ -6,7 +6,9 @@ class UpdateNsIdTherapyEventTransaction(val therapyEvent: TherapyEvent) : Transa
override fun run() { override fun run() {
val current = database.therapyEventDao.findById(therapyEvent.id) val current = database.therapyEventDao.findById(therapyEvent.id)
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId) if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId) {
database.therapyEventDao.updateExistingEntry(therapyEvent) current.interfaceIDs.nightscoutId = therapyEvent.interfaceIDs.nightscoutId
database.therapyEventDao.updateExistingEntry(current)
}
} }
} }