NSClientV3PluginTest #2
This commit is contained in:
parent
eb1fff54f1
commit
0873df5f56
|
@ -43,43 +43,43 @@ interface DataSyncSelector {
|
|||
fun resetToNextFullSync()
|
||||
|
||||
fun confirmLastBolusIdIfGreater(lastSynced: Long)
|
||||
fun processChangedBolusesCompat()
|
||||
fun processChangedBoluses()
|
||||
|
||||
fun confirmLastCarbsIdIfGreater(lastSynced: Long)
|
||||
fun processChangedCarbsCompat()
|
||||
fun processChangedCarbs()
|
||||
|
||||
fun confirmLastBolusCalculatorResultsIdIfGreater(lastSynced: Long)
|
||||
fun processChangedBolusCalculatorResultsCompat()
|
||||
fun processChangedBolusCalculatorResults()
|
||||
|
||||
fun confirmLastTempTargetsIdIfGreater(lastSynced: Long)
|
||||
fun processChangedTempTargetsCompat()
|
||||
fun processChangedTempTargets()
|
||||
|
||||
fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long)
|
||||
fun processChangedGlucoseValuesCompat()
|
||||
fun processChangedGlucoseValues()
|
||||
|
||||
fun confirmLastTherapyEventIdIfGreater(lastSynced: Long)
|
||||
fun processChangedTherapyEventsCompat()
|
||||
fun processChangedTherapyEvents()
|
||||
|
||||
fun confirmLastFoodIdIfGreater(lastSynced: Long)
|
||||
fun processChangedFoodsCompat()
|
||||
fun processChangedFoods()
|
||||
|
||||
fun confirmLastDeviceStatusIdIfGreater(lastSynced: Long)
|
||||
fun processChangedDeviceStatusesCompat()
|
||||
fun processChangedDeviceStatuses()
|
||||
|
||||
fun confirmLastTemporaryBasalIdIfGreater(lastSynced: Long)
|
||||
fun processChangedTemporaryBasalsCompat()
|
||||
fun processChangedTemporaryBasals()
|
||||
|
||||
fun confirmLastExtendedBolusIdIfGreater(lastSynced: Long)
|
||||
fun processChangedExtendedBolusesCompat()
|
||||
fun processChangedExtendedBoluses()
|
||||
|
||||
fun confirmLastProfileSwitchIdIfGreater(lastSynced: Long)
|
||||
fun processChangedProfileSwitchesCompat()
|
||||
fun processChangedProfileSwitches()
|
||||
|
||||
fun confirmLastEffectiveProfileSwitchIdIfGreater(lastSynced: Long)
|
||||
fun processChangedEffectiveProfileSwitchesCompat()
|
||||
fun processChangedEffectiveProfileSwitches()
|
||||
|
||||
fun confirmLastOfflineEventIdIfGreater(lastSynced: Long)
|
||||
fun processChangedOfflineEventsCompat()
|
||||
fun processChangedOfflineEvents()
|
||||
|
||||
fun confirmLastProfileStore(lastSynced: Long)
|
||||
fun processChangedProfileStore()
|
||||
|
|
|
@ -62,19 +62,19 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
|
||||
override fun doUpload() {
|
||||
if (sp.getBoolean(R.string.key_ns_upload, true) && !isPaused) {
|
||||
processChangedBolusesCompat()
|
||||
processChangedCarbsCompat()
|
||||
processChangedBolusCalculatorResultsCompat()
|
||||
processChangedTemporaryBasalsCompat()
|
||||
processChangedExtendedBolusesCompat()
|
||||
processChangedProfileSwitchesCompat()
|
||||
processChangedEffectiveProfileSwitchesCompat()
|
||||
processChangedGlucoseValuesCompat()
|
||||
processChangedTempTargetsCompat()
|
||||
processChangedFoodsCompat()
|
||||
processChangedTherapyEventsCompat()
|
||||
processChangedDeviceStatusesCompat()
|
||||
processChangedOfflineEventsCompat()
|
||||
processChangedBoluses()
|
||||
processChangedCarbs()
|
||||
processChangedBolusCalculatorResults()
|
||||
processChangedTemporaryBasals()
|
||||
processChangedExtendedBoluses()
|
||||
processChangedProfileSwitches()
|
||||
processChangedEffectiveProfileSwitches()
|
||||
processChangedGlucoseValues()
|
||||
processChangedTempTargets()
|
||||
processChangedFoods()
|
||||
processChangedTherapyEvents()
|
||||
processChangedDeviceStatuses()
|
||||
processChangedOfflineEvents()
|
||||
processChangedProfileStore()
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedBolusesCompat() {
|
||||
override tailrec fun processChangedBoluses() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastBolusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -123,14 +123,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
bolus.first.id == bolus.second.id && bolus.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Loaded from NS: ${bolus.second.id} ")
|
||||
confirmLastBolusIdIfGreater(bolus.second.id)
|
||||
processChangedBolusesCompat()
|
||||
processChangedBoluses()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
bolus.first.onlyNsIdAdded(bolus.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Bolus. Only NS id changed: ${bolus.second.id} ")
|
||||
confirmLastBolusIdIfGreater(bolus.second.id)
|
||||
processChangedBolusesCompat()
|
||||
processChangedBoluses()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -159,7 +159,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedCarbsCompat() {
|
||||
override tailrec fun processChangedCarbs() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastCarbsIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -176,14 +176,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
carb.first.id == carb.second.id && carb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Loaded from NS: ${carb.second.id} ")
|
||||
confirmLastCarbsIdIfGreater(carb.second.id)
|
||||
processChangedCarbsCompat()
|
||||
processChangedCarbs()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
carb.first.onlyNsIdAdded(carb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Carbs. Only NS id changed ID: ${carb.second.id} ")
|
||||
confirmLastCarbsIdIfGreater(carb.second.id)
|
||||
processChangedCarbsCompat()
|
||||
processChangedCarbs()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -208,7 +208,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedBolusCalculatorResultsCompat() {
|
||||
override tailrec fun processChangedBolusCalculatorResults() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastBolusCalculatorResultIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -225,14 +225,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
bolusCalculatorResult.first.id == bolusCalculatorResult.second.id && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Loaded from NS: ${bolusCalculatorResult.second.id} ")
|
||||
confirmLastBolusCalculatorResultsIdIfGreater(bolusCalculatorResult.second.id)
|
||||
processChangedBolusCalculatorResultsCompat()
|
||||
processChangedBolusCalculatorResults()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
bolusCalculatorResult.first.onlyNsIdAdded(bolusCalculatorResult.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring BolusCalculatorResult. Only NS id changed ID: ${bolusCalculatorResult.second.id} ")
|
||||
confirmLastBolusCalculatorResultsIdIfGreater(bolusCalculatorResult.second.id)
|
||||
processChangedBolusCalculatorResultsCompat()
|
||||
processChangedBolusCalculatorResults()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -260,7 +260,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTempTargetsCompat() {
|
||||
override tailrec fun processChangedTempTargets() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastTempTargetIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -277,14 +277,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
tt.first.id == tt.second.id && tt.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Loaded from NS: ${tt.second.id} ")
|
||||
confirmLastTempTargetsIdIfGreater(tt.second.id)
|
||||
processChangedTempTargetsCompat()
|
||||
processChangedTempTargets()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
tt.first.onlyNsIdAdded(tt.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryTarget. Only NS id changed ID: ${tt.second.id} ")
|
||||
confirmLastTempTargetsIdIfGreater(tt.second.id)
|
||||
processChangedTempTargetsCompat()
|
||||
processChangedTempTargets()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -313,7 +313,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedFoodsCompat() {
|
||||
override tailrec fun processChangedFoods() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastFoodIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -330,14 +330,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
food.first.id == food.second.id && food.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Loaded from NS: ${food.second.id} ")
|
||||
confirmLastFoodIdIfGreater(food.second.id)
|
||||
processChangedFoodsCompat()
|
||||
processChangedFoods()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
food.first.onlyNsIdAdded(food.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring Food. Only NS id changed ID: ${food.second.id} ")
|
||||
confirmLastFoodIdIfGreater(food.second.id)
|
||||
processChangedFoodsCompat()
|
||||
processChangedFoods()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -362,7 +362,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedGlucoseValuesCompat() {
|
||||
override tailrec fun processChangedGlucoseValues() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastGlucoseValueIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -380,14 +380,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
gv.first.id == gv.second.id && gv.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Loaded from NS: ${gv.second.id} ")
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
processChangedGlucoseValuesCompat()
|
||||
processChangedGlucoseValues()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
gv.first.onlyNsIdAdded(gv.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring GlucoseValue. Only NS id changed ID: ${gv.second.id} ")
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
processChangedGlucoseValuesCompat()
|
||||
processChangedGlucoseValues()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -403,7 +403,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
} else {
|
||||
confirmLastGlucoseValueIdIfGreater(gv.second.id)
|
||||
processChangedGlucoseValuesCompat()
|
||||
processChangedGlucoseValues()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTherapyEventsCompat() {
|
||||
override tailrec fun processChangedTherapyEvents() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastTherapyEventIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -433,14 +433,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
te.first.id == te.second.id && te.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Loaded from NS: ${te.second.id} ")
|
||||
confirmLastTherapyEventIdIfGreater(te.second.id)
|
||||
processChangedTherapyEventsCompat()
|
||||
processChangedTherapyEvents()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
te.first.onlyNsIdAdded(te.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TherapyEvent. Only NS id changed ID: ${te.second.id} ")
|
||||
confirmLastTherapyEventIdIfGreater(te.second.id)
|
||||
processChangedTherapyEventsCompat()
|
||||
processChangedTherapyEvents()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -465,7 +465,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun processChangedDeviceStatusesCompat() {
|
||||
override fun processChangedDeviceStatuses() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastDeviceStatusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -495,7 +495,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedTemporaryBasalsCompat() {
|
||||
override tailrec fun processChangedTemporaryBasals() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastTemporaryBasalIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -512,14 +512,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
tb.first.id == tb.second.id && tb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Loaded from NS: ${tb.second.id} ")
|
||||
confirmLastTemporaryBasalIdIfGreater(tb.second.id)
|
||||
processChangedTemporaryBasalsCompat()
|
||||
processChangedTemporaryBasals()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
tb.first.onlyNsIdAdded(tb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring TemporaryBasal. Only NS id changed ID: ${tb.second.id} ")
|
||||
confirmLastTemporaryBasalIdIfGreater(tb.second.id)
|
||||
processChangedTemporaryBasalsCompat()
|
||||
processChangedTemporaryBasals()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -548,7 +548,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedExtendedBolusesCompat() {
|
||||
override tailrec fun processChangedExtendedBoluses() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastExtendedBolusIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -567,14 +567,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
eb.first.id == eb.second.id && eb.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Loaded from NS: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
processChangedExtendedBoluses()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
eb.first.onlyNsIdAdded(eb.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. Only NS id changed ID: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
processChangedExtendedBoluses()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -596,7 +596,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
} else {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ExtendedBolus. No profile: ${eb.second.id} ")
|
||||
confirmLastExtendedBolusIdIfGreater(eb.second.id)
|
||||
processChangedExtendedBolusesCompat()
|
||||
processChangedExtendedBoluses()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -609,7 +609,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedProfileSwitchesCompat() {
|
||||
override tailrec fun processChangedProfileSwitches() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastProfileSwitchIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -626,14 +626,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
ps.first.id == ps.second.id && ps.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Loaded from NS: ${ps.second.id} ")
|
||||
confirmLastProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedProfileSwitchesCompat()
|
||||
processChangedProfileSwitches()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
ps.first.onlyNsIdAdded(ps.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring ProfileSwitch. Only NS id changed ID: ${ps.second.id} ")
|
||||
confirmLastProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedProfileSwitchesCompat()
|
||||
processChangedProfileSwitches()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -658,7 +658,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedEffectiveProfileSwitchesCompat() {
|
||||
override tailrec fun processChangedEffectiveProfileSwitches() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastEffectiveProfileSwitchIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -675,14 +675,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
ps.first.id == ps.second.id && ps.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Loaded from NS: ${ps.second.id} ")
|
||||
confirmLastEffectiveProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedEffectiveProfileSwitchesCompat()
|
||||
processChangedEffectiveProfileSwitches()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
ps.first.onlyNsIdAdded(ps.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring EffectiveProfileSwitch. Only NS id changed ID: ${ps.second.id} ")
|
||||
confirmLastEffectiveProfileSwitchIdIfGreater(ps.second.id)
|
||||
processChangedEffectiveProfileSwitchesCompat()
|
||||
processChangedEffectiveProfileSwitches()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
@ -711,7 +711,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override tailrec fun processChangedOfflineEventsCompat() {
|
||||
override tailrec fun processChangedOfflineEvents() {
|
||||
if (isPaused) return
|
||||
val lastDbIdWrapped = appRepository.getLastOfflineEventIdWrapped().blockingGet()
|
||||
val lastDbId = if (lastDbIdWrapped is ValueWrapper.Existing) lastDbIdWrapped.value else 0L
|
||||
|
@ -728,14 +728,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
oe.first.id == oe.second.id && oe.first.interfaceIDs.nightscoutId != null -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Loaded from NS: ${oe.second.id} ")
|
||||
confirmLastOfflineEventIdIfGreater(oe.second.id)
|
||||
processChangedOfflineEventsCompat()
|
||||
processChangedOfflineEvents()
|
||||
return
|
||||
}
|
||||
// only NsId changed, no need to upload
|
||||
oe.first.onlyNsIdAdded(oe.second) -> {
|
||||
aapsLogger.info(LTag.NSCLIENT, "Ignoring OfflineEvent. Only NS id changed ID: ${oe.second.id} ")
|
||||
confirmLastOfflineEventIdIfGreater(oe.second.id)
|
||||
processChangedOfflineEventsCompat()
|
||||
processChangedOfflineEvents()
|
||||
return
|
||||
}
|
||||
// without nsId = create new
|
||||
|
|
|
@ -63,7 +63,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TemporaryTarget " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTempTargetsCompat()
|
||||
dataSyncSelector.processChangedTempTargets()
|
||||
}
|
||||
|
||||
is PairGlucoseValue -> {
|
||||
|
@ -74,7 +74,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked GlucoseValue " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||
dataSyncSelector.processChangedGlucoseValues()
|
||||
}
|
||||
|
||||
is PairFood -> {
|
||||
|
@ -85,7 +85,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Food " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedFoodsCompat()
|
||||
dataSyncSelector.processChangedFoods()
|
||||
}
|
||||
|
||||
is PairTherapyEvent -> {
|
||||
|
@ -96,7 +96,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TherapyEvent " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||
dataSyncSelector.processChangedTherapyEvents()
|
||||
}
|
||||
|
||||
is PairBolus -> {
|
||||
|
@ -107,7 +107,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Bolus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusesCompat()
|
||||
dataSyncSelector.processChangedBoluses()
|
||||
}
|
||||
|
||||
is PairCarbs -> {
|
||||
|
@ -118,7 +118,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked Carbs " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedCarbsCompat()
|
||||
dataSyncSelector.processChangedCarbs()
|
||||
}
|
||||
|
||||
is PairBolusCalculatorResult -> {
|
||||
|
@ -129,7 +129,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked BolusCalculatorResult " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||
dataSyncSelector.processChangedBolusCalculatorResults()
|
||||
}
|
||||
|
||||
is PairTemporaryBasal -> {
|
||||
|
@ -140,7 +140,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked TemporaryBasal " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||
dataSyncSelector.processChangedTemporaryBasals()
|
||||
}
|
||||
|
||||
is PairExtendedBolus -> {
|
||||
|
@ -151,7 +151,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ExtendedBolus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||
dataSyncSelector.processChangedExtendedBoluses()
|
||||
}
|
||||
|
||||
is PairProfileSwitch -> {
|
||||
|
@ -162,7 +162,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked ProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedProfileSwitches()
|
||||
}
|
||||
|
||||
is PairEffectiveProfileSwitch -> {
|
||||
|
@ -173,7 +173,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked EffectiveProfileSwitch " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitches()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairDeviceStatus -> {
|
||||
|
@ -184,7 +184,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked DeviceStatus " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedDeviceStatusesCompat()
|
||||
dataSyncSelector.processChangedDeviceStatuses()
|
||||
}
|
||||
|
||||
is PairProfileStore -> {
|
||||
|
@ -200,7 +200,7 @@ class NSClientAddAckWorker(
|
|||
storeDataForDb.scheduleNsIdUpdate()
|
||||
rxBus.send(EventNSClientNewLog("DBADD", "Acked OfflineEvent " + pair.value.interfaceIDs.nightscoutId))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedOfflineEventsCompat()
|
||||
dataSyncSelector.processChangedOfflineEvents()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryTarget" + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTempTargetsCompat()
|
||||
dataSyncSelector.processChangedTempTargets()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked GlucoseValue " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||
dataSyncSelector.processChangedGlucoseValues()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastFoodIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Food " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedFoodsCompat()
|
||||
dataSyncSelector.processChangedFoods()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TherapyEvent " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||
dataSyncSelector.processChangedTherapyEvents()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastBolusIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Bolus " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusesCompat()
|
||||
dataSyncSelector.processChangedBoluses()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked Carbs " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedCarbsCompat()
|
||||
dataSyncSelector.processChangedCarbs()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked BolusCalculatorResult " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||
dataSyncSelector.processChangedBolusCalculatorResults()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked TemporaryBasal " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||
dataSyncSelector.processChangedTemporaryBasals()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ExtendedBolus " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||
dataSyncSelector.processChangedExtendedBoluses()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked ProfileSwitch " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedProfileSwitches()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastEffectiveProfileSwitchIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked EffectiveProfileSwitch " + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitches()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ class NSClientUpdateRemoveAckWorker(
|
|||
dataSyncSelector.confirmLastOfflineEventIdIfGreater(pair.id)
|
||||
rxBus.send(EventNSClientNewLog("DBUPDATE", "Acked OfflineEvent" + ack._id))
|
||||
// Send new if waiting
|
||||
dataSyncSelector.processChangedOfflineEventsCompat()
|
||||
dataSyncSelector.processChangedOfflineEvents()
|
||||
ret = Result.success(workDataOf("ProcessedData" to pair.toString()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,13 +346,13 @@ class NSClientV3Plugin @Inject constructor(
|
|||
return@launch
|
||||
}
|
||||
}
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdDeviceStatuses.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdDeviceStatuses.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastDeviceStatusIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedDeviceStatusesCompat()
|
||||
dataSyncSelector.processChangedDeviceStatuses()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
aapsLogger.error(LTag.NSCLIENT, "Upload exception", e)
|
||||
|
@ -397,13 +397,13 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairGlucoseValue -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdGlucoseValues.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdGlucoseValues.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedGlucoseValuesCompat()
|
||||
dataSyncSelector.processChangedGlucoseValues()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -451,13 +451,13 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairFood -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdFoods.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdFoods.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastFoodIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedFoodsCompat()
|
||||
dataSyncSelector.processChangedFoods()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
val profile = profileFunction.getProfile(dataPair.value.timestamp)
|
||||
if (profile == null) {
|
||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||
dataSyncSelector.processChangedTemporaryBasals()
|
||||
return
|
||||
}
|
||||
dataPair.value.toNSTemporaryBasal(profile)
|
||||
|
@ -494,7 +494,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
val profile = profileFunction.getProfile(dataPair.value.timestamp)
|
||||
if (profile == null) {
|
||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||
dataSyncSelector.processChangedExtendedBoluses()
|
||||
return
|
||||
}
|
||||
dataPair.value.toNSExtendedBolus(profile)
|
||||
|
@ -533,103 +533,103 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdBoluses.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdBoluses.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastBolusIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedBolusesCompat()
|
||||
dataSyncSelector.processChangedBoluses()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairCarbs -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdCarbs.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdCarbs.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedCarbsCompat()
|
||||
dataSyncSelector.processChangedCarbs()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdBolusCalculatorResults.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdBolusCalculatorResults.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedBolusCalculatorResultsCompat()
|
||||
dataSyncSelector.processChangedBolusCalculatorResults()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairTemporaryTarget -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdTemporaryTargets.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdTemporaryTargets.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastTempTargetsIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedTempTargetsCompat()
|
||||
dataSyncSelector.processChangedTempTargets()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairTherapyEvent -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdTherapyEvents.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdTherapyEvents.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedTherapyEventsCompat()
|
||||
dataSyncSelector.processChangedTherapyEvents()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairTemporaryBasal -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdTemporaryBasals.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdTemporaryBasals.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedTemporaryBasalsCompat()
|
||||
dataSyncSelector.processChangedTemporaryBasals()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairExtendedBolus -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdExtendedBoluses.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdExtendedBoluses.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastExtendedBolusIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedExtendedBolusesCompat()
|
||||
dataSyncSelector.processChangedExtendedBoluses()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairProfileSwitch -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdProfileSwitches.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdProfileSwitches.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastProfileSwitchIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedProfileSwitches()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairEffectiveProfileSwitch -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdEffectiveProfileSwitches.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdEffectiveProfileSwitches.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastEffectiveProfileSwitchIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitchesCompat()
|
||||
dataSyncSelector.processChangedEffectiveProfileSwitches()
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairOfflineEvent -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdOfflineEvents.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
// if (result.response == 201) { // created
|
||||
// dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
// storeDataForDb.nsIdOfflineEvents.add(dataPair.value)
|
||||
// storeDataForDb.scheduleNsIdUpdate()
|
||||
// }
|
||||
dataSyncSelector.confirmLastOfflineEventIdIfGreater(dataPair.id)
|
||||
dataSyncSelector.processChangedOfflineEventsCompat()
|
||||
dataSyncSelector.processChangedOfflineEvents()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ open class TestBaseWithProfile : TestBase() {
|
|||
@Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData
|
||||
@Mock lateinit var insulin: Insulin
|
||||
|
||||
lateinit var profileFunction: ProfileFunction
|
||||
open lateinit var profileFunction: ProfileFunction
|
||||
lateinit var dateUtil: DateUtil
|
||||
var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000)
|
||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.extensions.fromConstant
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
import info.nightscout.database.entities.Food
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.OfflineEvent
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.interfaces.XDripBroadcast
|
||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
|
@ -18,43 +28,32 @@ import info.nightscout.interfaces.sync.DataSyncSelector
|
|||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
|
||||
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
|
||||
import info.nightscout.sdk.interfaces.NSAndroidClient
|
||||
import info.nightscout.sdk.localmodel.treatment.CreateUpdateResponse
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.anyLong
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.internal.verification.Times
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class NSClientV3PluginTest : TestBase() {
|
||||
internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
||||
|
||||
@Mock lateinit var rxBus: RxBus
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var nsClientReceiverDelegate: NsClientReceiverDelegate
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var uiInteraction: UiInteraction
|
||||
@Mock lateinit var dataSyncSelector: DataSyncSelector
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var nsAndroidClient: NSAndroidClient
|
||||
@Mock lateinit var repository: AppRepository
|
||||
@Mock lateinit var uel: UserEntryLogger
|
||||
@Mock lateinit var nsClientSource: NSClientSource
|
||||
@Mock lateinit var xDripBroadcast: XDripBroadcast
|
||||
@Mock lateinit var virtualPump: VirtualPump
|
||||
@Mock lateinit var mockedProfileFunction: ProfileFunction
|
||||
|
||||
private lateinit var storeDataForDb: StoreDataForDb
|
||||
private lateinit var sut: NSClientV3Plugin
|
||||
|
@ -70,9 +69,10 @@ internal class NSClientV3PluginTest : TestBase() {
|
|||
sut =
|
||||
NSClientV3Plugin(
|
||||
injector, aapsLogger, aapsSchedulers, rxBus, rh, context, fabricPrivacy,
|
||||
sp, nsClientReceiverDelegate, config, dateUtil, uiInteraction, storeDataForDb, dataSyncSelector, profileFunction
|
||||
sp, nsClientReceiverDelegate, config, dateUtil, uiInteraction, storeDataForDb, dataSyncSelector, mockedProfileFunction
|
||||
)
|
||||
sut.nsAndroidClient = nsAndroidClient
|
||||
`when`(mockedProfileFunction.getProfile(anyLong())).thenReturn(validProfile)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -92,10 +92,431 @@ internal class NSClientV3PluginTest : TestBase() {
|
|||
configuration = "{\"insulin\":5,\"insulinConfiguration\":{},\"sensitivity\":2,\"sensitivityConfiguration\":{\"openapsama_min_5m_carbimpact\":8,\"absorption_cutoff\":4,\"autosens_max\":1.2,\"autosens_min\":0.7},\"overviewConfiguration\":{\"units\":\"mmol\",\"QuickWizard\":\"[]\",\"eatingsoon_duration\":60,\"eatingsoon_target\":4,\"activity_duration\":180,\"activity_target\":7.5,\"hypo_duration\":90,\"hypo_target\":8,\"low_mark\":3.9,\"high_mark\":10,\"statuslights_cage_warning\":72,\"statuslights_cage_critical\":96,\"statuslights_iage_warning\":120,\"statuslights_iage_critical\":150,\"statuslights_sage_warning\":168,\"statuslights_sage_critical\":336,\"statuslights_sbat_warning\":25,\"statuslights_sbat_critical\":5,\"statuslights_bage_warning\":720,\"statuslights_bage_critical\":800,\"statuslights_res_warning\":30,\"statuslights_res_critical\":10,\"statuslights_bat_warning\":50,\"statuslights_bat_critical\":25,\"boluswizard_percentage\":70},\"safetyConfiguration\":{\"age\":\"resistantadult\",\"treatmentssafety_maxbolus\":10,\"treatmentssafety_maxcarbs\":70}}"
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairDeviceStatus(deviceStatus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("devicestatus", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdDeviceStatuses.size)
|
||||
// Assertions.assertEquals(1, storeDataForDb.nsIdDeviceStatuses.size)
|
||||
verify(dataSyncSelector, Times(1)).confirmLastDeviceStatusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedDeviceStatusesCompat()
|
||||
verify(dataSyncSelector, Times(1)).processChangedDeviceStatuses()
|
||||
// update
|
||||
`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsAdd("devicestatus", dataPair, "1/3")
|
||||
// Assertions.assertEquals(1, storeDataForDb.nsIdDeviceStatuses.size) // still only 1
|
||||
verify(dataSyncSelector, Times(2)).confirmLastDeviceStatusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedDeviceStatuses()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddEntries() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val glucoseValue = GlucoseValue(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
raw = 101.0,
|
||||
value = 99.0,
|
||||
trendArrow = GlucoseValue.TrendArrow.DOUBLE_UP,
|
||||
noise = 1.0,
|
||||
sourceSensor = GlucoseValue.SourceSensor.DEXCOM_G4_WIXEL,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairGlucoseValue(glucoseValue, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createSvg(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("entries", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastGlucoseValueIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedGlucoseValues()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateSvg(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("entries", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastGlucoseValueIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedGlucoseValues()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddFood() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val food = Food(
|
||||
isValid = true,
|
||||
name = "name",
|
||||
category = "category",
|
||||
subCategory = "subcategory",
|
||||
portion = 2.0,
|
||||
carbs = 20,
|
||||
fat = 21,
|
||||
protein = 22,
|
||||
energy = 23,
|
||||
unit = "g",
|
||||
gi = 25,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairFood(food, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createFood(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("food", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastFoodIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedFoods()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateFood(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("food", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastFoodIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedFoods()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddBolus() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val bolus = Bolus(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
amount = 1.0,
|
||||
type = Bolus.Type.SMB,
|
||||
notes = "aaaa",
|
||||
isBasalInsulin = false,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairBolus(bolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastBolusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedBoluses()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastBolusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedBoluses()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddCarbs() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val carbs = Carbs(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
amount = 1.0,
|
||||
duration = 0,
|
||||
notes = "aaaa",
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairCarbs(carbs, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastCarbsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedCarbs()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastCarbsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedCarbs()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddBolusCalculatorResult() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val bolus = BolusCalculatorResult(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
targetBGLow = 110.0,
|
||||
targetBGHigh = 120.0,
|
||||
isf = 30.0,
|
||||
ic = 2.0,
|
||||
bolusIOB = 1.1,
|
||||
wasBolusIOBUsed = true,
|
||||
basalIOB = 1.2,
|
||||
wasBasalIOBUsed = true,
|
||||
glucoseValue = 150.0,
|
||||
wasGlucoseUsed = true,
|
||||
glucoseDifference = 30.0,
|
||||
glucoseInsulin = 1.3,
|
||||
glucoseTrend = 15.0,
|
||||
wasTrendUsed = true,
|
||||
trendInsulin = 1.4,
|
||||
cob = 24.0,
|
||||
wasCOBUsed = true,
|
||||
cobInsulin = 1.5,
|
||||
carbs = 36.0,
|
||||
wereCarbsUsed = true,
|
||||
carbsInsulin = 1.6,
|
||||
otherCorrection = 1.7,
|
||||
wasSuperbolusUsed = true,
|
||||
superbolusInsulin = 0.3,
|
||||
wasTempTargetUsed = false,
|
||||
totalInsulin = 9.1,
|
||||
percentageCorrection = 70,
|
||||
profileName = " sss",
|
||||
note = "ddd",
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairBolusCalculatorResult(bolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastBolusCalculatorResultsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedBolusCalculatorResults()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastBolusCalculatorResultsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedBolusCalculatorResults()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddEffectiveProfileSwitch() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val profileSwitch = EffectiveProfileSwitch(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
basalBlocks = validProfile.basalBlocks,
|
||||
isfBlocks = validProfile.isfBlocks,
|
||||
icBlocks = validProfile.icBlocks,
|
||||
targetBlocks = validProfile.targetBlocks,
|
||||
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.fromConstant(validProfile.units),
|
||||
originalProfileName = "SomeProfile",
|
||||
originalCustomizedName = "SomeProfile (150%, 1h)",
|
||||
originalTimeshift = 3600000,
|
||||
originalPercentage = 150,
|
||||
originalDuration = 3600000,
|
||||
originalEnd = 0,
|
||||
insulinConfiguration = activePlugin.activeInsulin.insulinConfiguration.also {
|
||||
it.insulinEndTime = (validProfile.dia * 3600 * 1000).toLong()
|
||||
},
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairEffectiveProfileSwitch(profileSwitch, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastEffectiveProfileSwitchIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedEffectiveProfileSwitches()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastEffectiveProfileSwitchIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedEffectiveProfileSwitches()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddProfileSwitch() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val profileSwitch = ProfileSwitch(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
basalBlocks = validProfile.basalBlocks,
|
||||
isfBlocks = validProfile.isfBlocks,
|
||||
icBlocks = validProfile.icBlocks,
|
||||
targetBlocks = validProfile.targetBlocks,
|
||||
glucoseUnit = ProfileSwitch.GlucoseUnit.fromConstant(validProfile.units),
|
||||
profileName = "SomeProfile",
|
||||
timeshift = 0,
|
||||
percentage = 100,
|
||||
duration = 0,
|
||||
insulinConfiguration = activePlugin.activeInsulin.insulinConfiguration.also {
|
||||
it.insulinEndTime = (validProfile.dia * 3600 * 1000).toLong()
|
||||
},
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairProfileSwitch(profileSwitch, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastProfileSwitchIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedProfileSwitches()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastProfileSwitchIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedProfileSwitches()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddExtendedBolus() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val extendedBolus = ExtendedBolus(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
amount = 2.0,
|
||||
isEmulatingTempBasal = false,
|
||||
duration = 3600000,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairExtendedBolus(extendedBolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastExtendedBolusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedExtendedBoluses()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastExtendedBolusIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedExtendedBoluses()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddOffilineEvent() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val offlineEvent = OfflineEvent(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
reason = OfflineEvent.Reason.DISCONNECT_PUMP,
|
||||
duration = 30000,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairOfflineEvent(offlineEvent, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastOfflineEventIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedOfflineEvents()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastOfflineEventIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedOfflineEvents()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddTemporaryBasal() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val temporaryBasal = TemporaryBasal(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
type = TemporaryBasal.Type.NORMAL,
|
||||
rate = 2.0,
|
||||
isAbsolute = true,
|
||||
duration = 3600000,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairTemporaryBasal(temporaryBasal, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastTemporaryBasalIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedTemporaryBasals()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastTemporaryBasalIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedTemporaryBasals()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddTemporaryTarget() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val temporaryTarget = TemporaryTarget(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
reason = TemporaryTarget.Reason.ACTIVITY,
|
||||
highTarget = 100.0,
|
||||
lowTarget = 99.0,
|
||||
duration = 3600000,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairTemporaryTarget(temporaryTarget, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastTempTargetsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedTempTargets()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastTempTargetsIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedTempTargets()
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
fun nsAddTherapyEvent() = runTest {
|
||||
sut.scope = CoroutineScope(UnconfinedTestDispatcher(testScheduler))
|
||||
val therapyEvent = TherapyEvent(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
type = TherapyEvent.Type.ANNOUNCEMENT,
|
||||
note = "ccccc",
|
||||
enteredBy = "dddd",
|
||||
glucose = 101.0,
|
||||
glucoseType = TherapyEvent.MeterType.FINGER,
|
||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL,
|
||||
duration = 3600000,
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
val dataPair = DataSyncSelector.PairTherapyEvent(therapyEvent, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, null))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(1)).confirmLastTherapyEventIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(1)).processChangedTherapyEvents()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, null))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
verify(dataSyncSelector, Times(2)).confirmLastTherapyEventIdIfGreater(1000)
|
||||
verify(dataSyncSelector, Times(2)).processChangedTherapyEvents()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue