NSC: fix duration sync
This commit is contained in:
parent
81a8080942
commit
d261bbad09
|
@ -5,7 +5,8 @@ import info.nightscout.database.entities.Carbs
|
||||||
/**
|
/**
|
||||||
* Sync the carbs from NS
|
* Sync the carbs from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsCarbsTransaction(private val carbs: List<Carbs>) : Transaction<SyncNsCarbsTransaction.TransactionResult>() {
|
class SyncNsCarbsTransaction(private val carbs: List<Carbs>, private val nsClientMode: Boolean) :
|
||||||
|
Transaction<SyncNsCarbsTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
val result = TransactionResult()
|
val result = TransactionResult()
|
||||||
|
@ -24,7 +25,7 @@ class SyncNsCarbsTransaction(private val carbs: List<Carbs>) : Transaction<SyncN
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
// and change duration
|
// and change duration
|
||||||
if (current.duration != carb.duration) {
|
if (current.duration != carb.duration && nsClientMode) {
|
||||||
current.amount = carb.amount
|
current.amount = carb.amount
|
||||||
current.duration = carb.duration
|
current.duration = carb.duration
|
||||||
database.carbsDao.updateExistingEntry(current)
|
database.carbsDao.updateExistingEntry(current)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import kotlin.math.abs
|
||||||
/**
|
/**
|
||||||
* Sync the Extended bolus from NS
|
* Sync the Extended bolus from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsExtendedBolusTransaction(private val extendedBoluses: List<ExtendedBolus>) :
|
class SyncNsExtendedBolusTransaction(private val extendedBoluses: List<ExtendedBolus>, private val nsClientMode: Boolean) :
|
||||||
Transaction<SyncNsExtendedBolusTransaction.TransactionResult>() {
|
Transaction<SyncNsExtendedBolusTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
|
@ -28,7 +28,7 @@ class SyncNsExtendedBolusTransaction(private val extendedBoluses: List<ExtendedB
|
||||||
database.extendedBolusDao.updateExistingEntry(current)
|
database.extendedBolusDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
if (current.duration != extendedBolus.duration) {
|
if (current.duration != extendedBolus.duration && nsClientMode) {
|
||||||
current.duration = extendedBolus.duration
|
current.duration = extendedBolus.duration
|
||||||
current.amount = extendedBolus.amount
|
current.amount = extendedBolus.amount
|
||||||
database.extendedBolusDao.updateExistingEntry(current)
|
database.extendedBolusDao.updateExistingEntry(current)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import kotlin.math.abs
|
||||||
/**
|
/**
|
||||||
* Sync the OfflineEvent from NS
|
* Sync the OfflineEvent from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsOfflineEventTransaction(private val offlineEvents: List<OfflineEvent>) :
|
class SyncNsOfflineEventTransaction(private val offlineEvents: List<OfflineEvent>, private val nsClientMode: Boolean) :
|
||||||
Transaction<SyncNsOfflineEventTransaction.TransactionResult>() {
|
Transaction<SyncNsOfflineEventTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
|
@ -28,7 +28,7 @@ class SyncNsOfflineEventTransaction(private val offlineEvents: List<OfflineEvent
|
||||||
database.offlineEventDao.updateExistingEntry(current)
|
database.offlineEventDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
if (current.duration != offlineEvent.duration) {
|
if (current.duration != offlineEvent.duration && nsClientMode) {
|
||||||
current.duration = offlineEvent.duration
|
current.duration = offlineEvent.duration
|
||||||
database.offlineEventDao.updateExistingEntry(current)
|
database.offlineEventDao.updateExistingEntry(current)
|
||||||
result.updatedDuration.add(current)
|
result.updatedDuration.add(current)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import kotlin.math.abs
|
||||||
/**
|
/**
|
||||||
* Sync the Temporary Basal from NS
|
* Sync the Temporary Basal from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsTemporaryBasalTransaction(private val temporaryBasals: List<TemporaryBasal>) : Transaction<SyncNsTemporaryBasalTransaction.TransactionResult>() {
|
class SyncNsTemporaryBasalTransaction(private val temporaryBasals: List<TemporaryBasal>, private val nsClientMode: Boolean) : Transaction<SyncNsTemporaryBasalTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
val result = TransactionResult()
|
val result = TransactionResult()
|
||||||
|
@ -28,7 +28,7 @@ class SyncNsTemporaryBasalTransaction(private val temporaryBasals: List<Temporar
|
||||||
database.temporaryBasalDao.updateExistingEntry(current)
|
database.temporaryBasalDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
if (current.duration != temporaryBasal.duration) {
|
if (current.duration != temporaryBasal.duration && nsClientMode) {
|
||||||
current.duration = temporaryBasal.duration
|
current.duration = temporaryBasal.duration
|
||||||
database.temporaryBasalDao.updateExistingEntry(current)
|
database.temporaryBasalDao.updateExistingEntry(current)
|
||||||
result.updatedDuration.add(current)
|
result.updatedDuration.add(current)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import kotlin.math.abs
|
||||||
/**
|
/**
|
||||||
* Sync the TemporaryTarget from NS
|
* Sync the TemporaryTarget from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsTemporaryTargetTransaction(private val temporaryTargets: List<TemporaryTarget>) :
|
class SyncNsTemporaryTargetTransaction(private val temporaryTargets: List<TemporaryTarget>, private val nsClientMode: Boolean) :
|
||||||
Transaction<SyncNsTemporaryTargetTransaction.TransactionResult>() {
|
Transaction<SyncNsTemporaryTargetTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
|
@ -28,7 +28,7 @@ class SyncNsTemporaryTargetTransaction(private val temporaryTargets: List<Tempor
|
||||||
database.temporaryTargetDao.updateExistingEntry(current)
|
database.temporaryTargetDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
if (current.duration != temporaryTarget.duration) {
|
if (current.duration != temporaryTarget.duration && nsClientMode) {
|
||||||
current.duration = temporaryTarget.duration
|
current.duration = temporaryTarget.duration
|
||||||
database.temporaryTargetDao.updateExistingEntry(current)
|
database.temporaryTargetDao.updateExistingEntry(current)
|
||||||
result.updatedDuration.add(current)
|
result.updatedDuration.add(current)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import info.nightscout.database.entities.TherapyEvent
|
||||||
/**
|
/**
|
||||||
* Sync the TherapyEvents from NS
|
* Sync the TherapyEvents from NS
|
||||||
*/
|
*/
|
||||||
class SyncNsTherapyEventTransaction(private val therapyEvents: List<TherapyEvent>) :
|
class SyncNsTherapyEventTransaction(private val therapyEvents: List<TherapyEvent>, private val nsClientMode: Boolean) :
|
||||||
Transaction<SyncNsTherapyEventTransaction.TransactionResult>() {
|
Transaction<SyncNsTherapyEventTransaction.TransactionResult>() {
|
||||||
|
|
||||||
override fun run(): TransactionResult {
|
override fun run(): TransactionResult {
|
||||||
|
@ -24,7 +24,7 @@ class SyncNsTherapyEventTransaction(private val therapyEvents: List<TherapyEvent
|
||||||
database.therapyEventDao.updateExistingEntry(current)
|
database.therapyEventDao.updateExistingEntry(current)
|
||||||
result.invalidated.add(current)
|
result.invalidated.add(current)
|
||||||
}
|
}
|
||||||
if (current.duration != therapyEvent.duration) {
|
if (current.duration != therapyEvent.duration && nsClientMode) {
|
||||||
current.duration = therapyEvent.duration
|
current.duration = therapyEvent.duration
|
||||||
database.therapyEventDao.updateExistingEntry(current)
|
database.therapyEventDao.updateExistingEntry(current)
|
||||||
result.updatedDuration.add(current)
|
result.updatedDuration.add(current)
|
||||||
|
|
|
@ -202,7 +202,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
SystemClock.sleep(pause)
|
SystemClock.sleep(pause)
|
||||||
|
|
||||||
if (carbs.isNotEmpty())
|
if (carbs.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsCarbsTransaction(carbs))
|
repository.runTransactionForResult(SyncNsCarbsTransaction(carbs, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
SystemClock.sleep(pause)
|
SystemClock.sleep(pause)
|
||||||
|
|
||||||
if (temporaryTargets.isNotEmpty())
|
if (temporaryTargets.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTargets))
|
repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTargets, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
SystemClock.sleep(pause)
|
SystemClock.sleep(pause)
|
||||||
|
|
||||||
if (temporaryBasals.isNotEmpty())
|
if (temporaryBasals.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsTemporaryBasalTransaction(temporaryBasals))
|
repository.runTransactionForResult(SyncNsTemporaryBasalTransaction(temporaryBasals, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary basal", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving temporary basal", it)
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (therapyEvents.isNotEmpty())
|
if (therapyEvents.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvents))
|
repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvents, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
SystemClock.sleep(pause)
|
SystemClock.sleep(pause)
|
||||||
|
|
||||||
if (offlineEvents.isNotEmpty())
|
if (offlineEvents.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsOfflineEventTransaction(offlineEvents))
|
repository.runTransactionForResult(SyncNsOfflineEventTransaction(offlineEvents, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving OfflineEvent", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving OfflineEvent", it)
|
||||||
}
|
}
|
||||||
|
@ -653,7 +653,7 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
SystemClock.sleep(pause)
|
SystemClock.sleep(pause)
|
||||||
|
|
||||||
if (extendedBoluses.isNotEmpty())
|
if (extendedBoluses.isNotEmpty())
|
||||||
repository.runTransactionForResult(SyncNsExtendedBolusTransaction(extendedBoluses))
|
repository.runTransactionForResult(SyncNsExtendedBolusTransaction(extendedBoluses, config.NSCLIENT))
|
||||||
.doOnError {
|
.doOnError {
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving extended bolus", it)
|
aapsLogger.error(LTag.DATABASE, "Error while saving extended bolus", it)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue