Remove instead of invalidate uncertain Omnipod TBR after recovery
This commit is contained in:
parent
cab349dd0a
commit
eff37e8c33
6 changed files with 40 additions and 31 deletions
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
|
|||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
|
@ -27,8 +28,10 @@ class TreatmentsPluginHistory @Inject constructor(
|
|||
profileFunction: ProfileFunction,
|
||||
activePlugin: ActivePluginProvider,
|
||||
nsUpload: NSUpload,
|
||||
fabricPrivacy: FabricPrivacy, dateUtil: DateUtil
|
||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) {
|
||||
fabricPrivacy: FabricPrivacy,
|
||||
dateUtil: DateUtil,
|
||||
uploadQueue: UploadQueue
|
||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
|
||||
|
||||
init {
|
||||
onStart()
|
||||
|
|
|
@ -30,13 +30,12 @@ import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
|||
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.ProfileIntervals;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventReloadProfileSwitchData;
|
||||
import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
||||
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
||||
|
@ -45,13 +44,15 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||
|
@ -75,6 +76,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
private final ProfileFunction profileFunction;
|
||||
private final ActivePluginProvider activePlugin;
|
||||
private final NSUpload nsUpload;
|
||||
private final UploadQueue uploadQueue;
|
||||
private final FabricPrivacy fabricPrivacy;
|
||||
private final DateUtil dateUtil;
|
||||
|
||||
|
@ -103,7 +105,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
ActivePluginProvider activePlugin,
|
||||
NSUpload nsUpload,
|
||||
FabricPrivacy fabricPrivacy,
|
||||
DateUtil dateUtil
|
||||
DateUtil dateUtil,
|
||||
UploadQueue uploadQueue
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.TREATMENT)
|
||||
|
@ -124,6 +127,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
this.fabricPrivacy = fabricPrivacy;
|
||||
this.dateUtil = dateUtil;
|
||||
this.nsUpload = nsUpload;
|
||||
this.uploadQueue = uploadQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -338,8 +342,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: NOTHING FOUND");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
|
@ -350,8 +353,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: NOTHING FOUND");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
|
@ -362,8 +364,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: NOTHING FOUND");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
|
@ -387,6 +388,16 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
return getTempBasalFromHistory(System.currentTimeMillis()) != null;
|
||||
}
|
||||
|
||||
@Override public void removeTempBasal(TemporaryBasal tempBasal) {
|
||||
String tempBasalId = tempBasal._id;
|
||||
if (NSUpload.isIdValid(tempBasalId)) {
|
||||
nsUpload.removeCareportalEntryFromNS(tempBasalId);
|
||||
} else {
|
||||
uploadQueue.removeID("dbAdd", tempBasalId);
|
||||
}
|
||||
MainApp.getDbHelper().delete(tempBasal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInHistoryExtendedBoluslInProgress() {
|
||||
return getExtendedBolusFromHistory(System.currentTimeMillis()) != null; //TODO: crosscheck here
|
||||
|
|
|
@ -11,7 +11,6 @@ import androidx.cardview.widget.CardView
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.Intervals
|
||||
import info.nightscout.androidaps.data.IobTotal
|
||||
|
@ -19,33 +18,29 @@ import info.nightscout.androidaps.db.Source
|
|||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTemporaryBasalsFragment.RecyclerViewAdapter.TempBasalsViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.treatments_tempbasals_fragment.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var nsUpload: NSUpload
|
||||
@Inject lateinit var uploadQueue: UploadQueue
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
@ -81,6 +76,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
inner class RecyclerViewAdapter internal constructor(private var tempBasalList: Intervals<TemporaryBasal>) : RecyclerView.Adapter<TempBasalsViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): TempBasalsViewHolder {
|
||||
val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.treatments_tempbasals_item, viewGroup, false)
|
||||
return TempBasalsViewHolder(v)
|
||||
|
@ -142,6 +138,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
inner class TempBasalsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
var cv: CardView = itemView.findViewById(R.id.tempbasals_cardview)
|
||||
var date: TextView = itemView.findViewById(R.id.tempbasals_date)
|
||||
var duration: TextView = itemView.findViewById(R.id.tempbasals_duration)
|
||||
|
@ -166,10 +163,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.date)}
|
||||
""".trimIndent(),
|
||||
DialogInterface.OnClickListener { _: DialogInterface?, _: Int ->
|
||||
val id = tempBasal._id
|
||||
if (NSUpload.isIdValid(id)) nsUpload.removeCareportalEntryFromNS(id)
|
||||
else uploadQueue.removeID("dbAdd", id)
|
||||
MainApp.getDbHelper().delete(tempBasal)
|
||||
activePlugin.activeTreatments.removeTempBasal(tempBasal)
|
||||
}, null)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@ import info.nightscout.androidaps.MainApp
|
|||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.db.TDD
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
|
@ -34,8 +35,9 @@ class TddCalculator @Inject constructor(
|
|||
val profileFunction: ProfileFunction,
|
||||
fabricPrivacy: FabricPrivacy,
|
||||
nsUpload: NSUpload,
|
||||
private val dateUtil: DateUtil
|
||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) {
|
||||
private val dateUtil: DateUtil,
|
||||
uploadQueue: UploadQueue
|
||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
|
||||
|
||||
init {
|
||||
service = TreatmentService(injector) // plugin is not started
|
||||
|
|
|
@ -55,6 +55,8 @@ public interface TreatmentsInterface {
|
|||
|
||||
NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory();
|
||||
|
||||
void removeTempBasal(TemporaryBasal temporaryBasal);
|
||||
|
||||
boolean isInHistoryExtendedBoluslInProgress();
|
||||
|
||||
ExtendedBolus getExtendedBolusFromHistory(long time);
|
||||
|
|
|
@ -396,11 +396,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
|||
rxBus.send(new EventNewNotification(new Notification(Notification.OMNIPOD_PUMP_ALARM, resourceHelper.gs(R.string.omnipod_error_tbr_running_but_aaps_not_aware), Notification.NORMAL).sound(R.raw.boluserror)));
|
||||
}
|
||||
} else if (!podStateManager.isTempBasalRunning() && tempBasal != null) {
|
||||
aapsLogger.warn(LTag.PUMP, "Invalidating AAPS TBR that actually hadn't succeeded");
|
||||
|
||||
tempBasal.isValid = false;
|
||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
||||
handleCancelledTbr();
|
||||
aapsLogger.warn(LTag.PUMP, "Removing AAPS TBR that actually hadn't succeeded");
|
||||
activePlugin.getActiveTreatments().removeTempBasal(tempBasal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue