do not show notification for old TDD data

This commit is contained in:
Milos Kozak 2021-11-02 13:41:55 +01:00
parent 87679b42e7
commit bc14496cbd

View file

@ -51,7 +51,7 @@ class PumpSyncImplementation @Inject constructor(
* @param serialNumber serial number of of pump
* @return true if data is allowed
*/
private fun confirmActivePump(timestamp: Long, type: PumpType, serialNumber: String): Boolean {
private fun confirmActivePump(timestamp: Long, type: PumpType, serialNumber: String, showNotification: Boolean = true): Boolean {
val storedType = sp.getString(R.string.key_active_pump_type, "")
val storedSerial = sp.getString(R.string.key_active_pump_serial_number, "")
val storedTimestamp = sp.getLong(R.string.key_active_pump_change_timestamp, 0L)
@ -70,7 +70,7 @@ class PumpSyncImplementation @Inject constructor(
return true
}
if ((type.description != storedType || serialNumber != storedSerial) && timestamp >= storedTimestamp)
if (showNotification && (type.description != storedType || serialNumber != storedSerial) && timestamp >= storedTimestamp)
rxBus.send(EventNewNotification(Notification(Notification.WRONG_PUMP_DATA, resourceHelper.gs(R.string.wrong_pump_data), Notification.URGENT)))
aapsLogger.error(LTag.PUMP, "Ignoring pump history record Allowed: ${dateUtil.dateAndTimeAndSecondsString(storedTimestamp)} $storedType $storedSerial Received: $timestamp ${dateUtil.dateAndTimeAndSecondsString(timestamp)} ${type.description} $serialNumber")
return false
@ -397,7 +397,8 @@ class PumpSyncImplementation @Inject constructor(
}
override fun createOrUpdateTotalDailyDose(timestamp: Long, bolusAmount: Double, basalAmount: Double, totalAmount: Double, pumpId: Long?, pumpType: PumpType, pumpSerial: String): Boolean {
if (!confirmActivePump(timestamp, pumpType, pumpSerial)) return false
// there are probably old data in pump -> do not show notification, just ignore
if (!confirmActivePump(timestamp, pumpType, pumpSerial, showNotification = false)) return false
val tdd = TotalDailyDose(
timestamp = timestamp,
bolusAmount = bolusAmount,