allow bolus update in NSC mode
This commit is contained in:
parent
7f3f1c6c8b
commit
ac62217984
|
@ -98,7 +98,10 @@ class NSClientAddUpdateWorker(
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it")
|
||||||
}
|
}
|
||||||
result.updatedNsId.forEach {
|
result.updatedNsId.forEach {
|
||||||
aapsLogger.debug(LTag.DATABASE, "Updated nsId bolus $it")
|
aapsLogger.debug(LTag.DATABASE, "Updated nsId of bolus $it")
|
||||||
|
}
|
||||||
|
result.updated.forEach {
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Updated amount of bolus $it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: aapsLogger.error("Error parsing bolus json $json")
|
} ?: aapsLogger.error("Error parsing bolus json $json")
|
||||||
|
|
|
@ -16,21 +16,27 @@ class SyncNsBolusTransaction(private val bolus: Bolus) : Transaction<SyncNsBolus
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
// nsId exists, allow only invalidation
|
// nsId exists, allow only invalidation or amount update (for drivers setting full amount upfront)
|
||||||
if (current.isValid && !bolus.isValid) {
|
if (current.isValid && !bolus.isValid) {
|
||||||
current.isValid = false
|
current.isValid = false
|
||||||
database.bolusDao.updateExistingEntry(current)
|
database.bolusDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
|
if (current.amount != bolus.amount) {
|
||||||
|
current.amount = bolus.amount
|
||||||
|
database.bolusDao.updateExistingEntry(current)
|
||||||
|
result.updated.add(current)
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// not known nsId
|
// not known nsId
|
||||||
val existing = database.bolusDao.findByTimestamp(bolus.timestamp)
|
val existing = database.bolusDao.findByTimestamp(bolus.timestamp)
|
||||||
if (existing != null && existing.interfaceIDs.nightscoutId == null) {
|
if (existing != null && existing.interfaceIDs.nightscoutId == null) {
|
||||||
// the same record, update nsId only
|
// the same record, update nsId only and amount
|
||||||
existing.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
existing.interfaceIDs.nightscoutId = bolus.interfaceIDs.nightscoutId
|
||||||
existing.isValid = bolus.isValid
|
existing.isValid = bolus.isValid
|
||||||
|
existing.amount = bolus.amount
|
||||||
database.bolusDao.updateExistingEntry(existing)
|
database.bolusDao.updateExistingEntry(existing)
|
||||||
result.updatedNsId.add(existing)
|
result.updatedNsId.add(existing)
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,5 +52,6 @@ class SyncNsBolusTransaction(private val bolus: Bolus) : Transaction<SyncNsBolus
|
||||||
val updatedNsId = mutableListOf<Bolus>()
|
val updatedNsId = mutableListOf<Bolus>()
|
||||||
val inserted = mutableListOf<Bolus>()
|
val inserted = mutableListOf<Bolus>()
|
||||||
val invalidated = mutableListOf<Bolus>()
|
val invalidated = mutableListOf<Bolus>()
|
||||||
|
val updated = mutableListOf<Bolus>()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue