Merge branch 'meallink' of https://github.com/nightscout/AndroidAPS into meallink

This commit is contained in:
Milos Kozak 2021-04-13 18:35:15 +02:00
commit 429842ecd0
15 changed files with 127 additions and 163 deletions

View file

@ -214,8 +214,8 @@ class InsulinDialog : DialogFragmentWithDate() {
detailedBolusInfo.timestamp = time
if (recordOnlyChecked) {
uel.log(Action.BOLUS, Sources.InsulinDialog,
notes,
ValueWithUnit.StringResource(R.string.record),
resourceHelper.gs(R.string.record) + if (notes.isNotEmpty()) ": " + notes else "",
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.record)),
ValueWithUnit.Insulin(insulinAfterConstraints),
ValueWithUnit.Minute(timeOffset).takeIf { timeOffset!= 0 })
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
@ -224,15 +224,14 @@ class InsulinDialog : DialogFragmentWithDate() {
{ aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) }
)
} else {
uel.log(Action.BOLUS, Sources.InsulinDialog,
notes,
ValueWithUnit.Insulin(insulinAfterConstraints))
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), info.nightscout.androidaps.dana.R.raw.boluserror)
} else
uel.log(Action.BOLUS, Sources.InsulinDialog,
notes,
ValueWithUnit.Insulin(insulinAfterConstraints))
}
}
})
}

View file

@ -149,9 +149,9 @@ class TreatmentDialog : DialogFragmentWithDate() {
detailedBolusInfo.carbs = carbsAfterConstraints.toDouble()
detailedBolusInfo.context = context
if (recordOnlyChecked) {
uel.log(action, Sources.TreatmentDialog,
uel.log(action, Sources.TreatmentDialog, if (insulinAfterConstraints != 0.0) resourceHelper.gs(R.string.record) else "",
ValueWithUnit.Timestamp(detailedBolusInfo.timestamp).takeIf { eventTimeChanged },
ValueWithUnit.StringResource(R.string.record).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.record)).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 },
ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbsAfterConstraints != 0 })
if (detailedBolusInfo.insulin > 0)

View file

@ -378,8 +378,9 @@ open class LoopPlugin @Inject constructor(
// mId allows you to update the notification later on.
mNotificationManager.notify(Constants.notificationID, builder.build())
uel.log(Action.CAREPORTAL, Sources.Loop,
ValueWithUnit.StringResource(info.nightscout.androidaps.core.R.string.carbsreq, listOf(ValueWithUnit.Gram(resultAfterConstraints.carbsReq), ValueWithUnit.Minute(resultAfterConstraints.carbsReqWithin))))
uel.log(Action.CAREPORTAL, Sources.Loop, resourceHelper.gs(R.string.carbsreq, resultAfterConstraints.carbsReq, resultAfterConstraints.carbsReqWithin),
ValueWithUnit.Gram(resultAfterConstraints.carbsReq),
ValueWithUnit.Minute(resultAfterConstraints.carbsReqWithin))
rxBus.send(EventNewOpenLoopNotification())
//only send to wear if Native notifications are turned off

View file

@ -148,8 +148,8 @@ class ConfigBuilderPlugin @Inject constructor(
performPluginSwitch(changedPlugin, newState, type)
pumpSync.connectNewPump()
sp.putBoolean("allow_hardware_pump", true)
uel.log(Action.HW_PUMP_ALLOWED, Sources.ConfigBuilder,
ValueWithUnit.StringResource(changedPlugin.pluginDescription.pluginName))
uel.log(Action.HW_PUMP_ALLOWED, Sources.ConfigBuilder, resourceHelper.gs(changedPlugin.pluginDescription.pluginName),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(changedPlugin.pluginDescription.pluginName)))
aapsLogger.debug(LTag.PUMP, "First time HW pump allowed!")
}, {
rxBus.send(EventConfigBuilderUpdateGui())
@ -160,12 +160,12 @@ class ConfigBuilderPlugin @Inject constructor(
override fun performPluginSwitch(changedPlugin: PluginBase, enabled: Boolean, type: PluginType) {
if(enabled && !changedPlugin.isEnabled()) {
uel.log(Action.PLUGIN_ENABLED, Sources.ConfigBuilder,
ValueWithUnit.StringResource(changedPlugin.pluginDescription.pluginName))
uel.log(Action.PLUGIN_ENABLED, Sources.ConfigBuilder, resourceHelper.gs(changedPlugin.pluginDescription.pluginName),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(changedPlugin.pluginDescription.pluginName)))
}
else if(!enabled) {
uel.log(Action.PLUGIN_DISABLED, Sources.ConfigBuilder,
ValueWithUnit.StringResource(changedPlugin.pluginDescription.pluginName))
uel.log(Action.PLUGIN_DISABLED, Sources.ConfigBuilder, resourceHelper.gs(changedPlugin.pluginDescription.pluginName),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(changedPlugin.pluginDescription.pluginName)))
}
changedPlugin.setPluginEnabled(type, enabled)
changedPlugin.setFragmentVisible(type, enabled)

View file

@ -76,8 +76,8 @@ class FoodFragment : DaggerFragment() {
binding.refreshFromNightscout.setOnClickListener {
context?.let { context ->
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", {
uel.log(Action.FOOD, Sources.Food,
ValueWithUnit.StringResource(R.string.refresheventsfromnightscout))
uel.log(Action.FOOD, Sources.Food, resourceHelper.gs(R.string.refresheventsfromnightscout),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.refresheventsfromnightscout)))
disposable += Completable.fromAction { repository.deleteAllFoods() }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)

View file

@ -587,8 +587,8 @@ class SmsCommunicatorPlugin @Inject constructor(
activePlugin.activeTreatments.doProfileSwitch(store, list[pIndex - 1] as String, 0, finalPercentage, 0, dateUtil.now())
val replyText = resourceHelper.gs(R.string.profileswitchcreated)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.PROFILE_SWITCH, Sources.SMS,
ValueWithUnit.StringResource(R.string.profileswitchcreated))
uel.log(Action.PROFILE_SWITCH, Sources.SMS, resourceHelper.gs(R.string.profileswitchcreated),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.profileswitchcreated)))
}
})
}
@ -610,14 +610,14 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalcanceled))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_tempbasalcanceled)))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalcancelfailed))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_tempbasalcancelfailed)))
}
}
})
@ -647,18 +647,20 @@ class SmsCommunicatorPlugin @Inject constructor(
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent)
uel.log(Action.TEMP_BASAL, Sources.SMS,
activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset_percent, listOf(ValueWithUnit.Percent(result.percent), ValueWithUnit.Minute(result.duration))) )
activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalset_percent, result.percent, result.duration),
ValueWithUnit.Percent(result.percent),
ValueWithUnit.Minute(result.duration))
else
uel.log(Action.TEMP_BASAL, Sources.SMS,
activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset, listOf( ValueWithUnit.UnitPerHour(result.absolute), ValueWithUnit.Minute(result.duration))))
activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalset, result.absolute, result.duration),
ValueWithUnit.UnitPerHour(result.absolute),
ValueWithUnit.Minute(result.duration))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalfailed))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_tempbasalfailed)))
}
}
})
@ -689,17 +691,19 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent)
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset_percent, listOf(ValueWithUnit.Percent(result.percent), ValueWithUnit.Minute(result.duration))))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalset_percent, result.percent, result.duration),
ValueWithUnit.Percent(result.percent),
ValueWithUnit.Minute(result.duration))
else
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalset, listOf(ValueWithUnit.UnitPerHour(result.absolute), ValueWithUnit.Minute(result.duration))))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalset, result.absolute, result.duration),
ValueWithUnit.UnitPerHour(result.absolute),
ValueWithUnit.Minute(result.duration))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_tempbasalfailed))
uel.log(Action.TEMP_BASAL, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_tempbasalfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_tempbasalfailed)))
}
}
})
@ -726,8 +730,8 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcancelfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedcanceled))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_extendedcanceled),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_extendedcanceled)))
}
}
})
@ -754,18 +758,20 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (config.APS)
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedset, listOf(ValueWithUnit.Insulin(aDouble ?: 0.0), ValueWithUnit.Minute(duration))),
ValueWithUnit.StringResource(R.string.loopsuspended))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_extendedset, aDouble, duration) + " / " + resourceHelper.gs(R.string.loopsuspended),
ValueWithUnit.Insulin(aDouble ?: 0.0),
ValueWithUnit.Minute(duration),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.loopsuspended)))
else
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedset, listOf( ValueWithUnit.Insulin(aDouble ?: 0.0), ValueWithUnit.Minute(duration))))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_extendedset, aDouble, duration),
ValueWithUnit.Insulin(aDouble ?: 0.0),
ValueWithUnit.Minute(duration))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_extendedfailed))
uel.log(Action.EXTENDED_BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_extendedfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_extendedfailed)))
}
}
})
@ -842,8 +848,8 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = resourceHelper.gs(R.string.smscommunicator_bolusfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_bolusfailed))
uel.log(Action.BOLUS, Sources.SMS, activePlugin.activePump.shortStatus(true) + "\n" + resourceHelper.gs(R.string.smscommunicator_bolusfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_bolusfailed)))
}
}
})
@ -900,14 +906,14 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_carbsset, listOf(ValueWithUnit.Gram(anInteger ?: 0))))
uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true) + ": " + resourceHelper.gs(R.string.smscommunicator_carbsset, anInteger),
ValueWithUnit.Gram(anInteger ?: 0))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed, anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true),
ValueWithUnit.StringResource(R.string.smscommunicator_carbsfailed, listOf(ValueWithUnit.Gram(anInteger ?: 0))))
uel.log(Action.CARBS, Sources.SMS, activePlugin.activePump.shortStatus(true) + ": " + resourceHelper.gs(R.string.smscommunicator_carbsfailed, anInteger),
ValueWithUnit.Gram(anInteger ?: 0))
}
}
})
@ -997,8 +1003,8 @@ class SmsCommunicatorPlugin @Inject constructor(
})
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_canceled))
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.CANCEL_TT, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_tt_canceled))
uel.log(Action.CANCEL_TT, Sources.SMS, resourceHelper.gs(R.string.smscommunicator_tt_canceled),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_tt_canceled)))
}
})
} else
@ -1017,8 +1023,8 @@ class SmsCommunicatorPlugin @Inject constructor(
sp.putBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_stoppedsms))
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.STOP_SMS, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_stoppedsms))
uel.log(Action.STOP_SMS, Sources.SMS, resourceHelper.gs(R.string.smscommunicator_stoppedsms),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_stoppedsms)))
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
@ -1037,11 +1043,11 @@ class SmsCommunicatorPlugin @Inject constructor(
if (result) resourceHelper.gs(R.string.smscommunicator_calibrationsent) else resourceHelper.gs(R.string.smscommunicator_calibrationfailed)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result)
uel.log(Action.CALIBRATION, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_calibrationsent))
uel.log(Action.CALIBRATION, Sources.SMS, resourceHelper.gs(R.string.smscommunicator_calibrationsent),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_calibrationsent)))
else
uel.log(Action.CALIBRATION, Sources.SMS,
ValueWithUnit.StringResource(R.string.smscommunicator_calibrationfailed))
uel.log(Action.CALIBRATION, Sources.SMS, resourceHelper.gs(R.string.smscommunicator_calibrationfailed),
ValueWithUnit.SimpleString(resourceHelper.gsNotLocalised(R.string.smscommunicator_calibrationfailed)))
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))

View file

@ -37,8 +37,8 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) {
if (!loopPlugin.isSuspended) {
loopPlugin.suspendLoop(minutes.getMinutes())
rxBus.send(EventRefreshOverview("ActionLoopSuspend"))
uel.log(UserEntry.Action.SUSPEND, Sources.Automation, title,
ValueWithUnit.StringResource(R.string.suspendloopforXmin, listOf(ValueWithUnit.Minute(minutes.getMinutes()))))
uel.log(UserEntry.Action.SUSPEND, Sources.Automation, title + ": " + resourceHelper.gs(R.string.suspendloopforXmin, minutes.getMinutes()),
ValueWithUnit.Minute(minutes.getMinutes()))
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
} else {
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadysuspended))?.run()

View file

@ -42,8 +42,9 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector
}
override fun doAction(callback: Callback) {
uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title,
ValueWithUnit.StringResource( R.string.startprofile, listOf(ValueWithUnit.Percent(pct.value.toInt()), ValueWithUnit.Minute(duration.value))))
uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title + ": " + resourceHelper.gs(R.string.startprofile, pct.value.toInt(), duration.value),
ValueWithUnit.Percent(pct.value.toInt()),
ValueWithUnit.Minute(duration.value))
activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0)
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
}

View file

@ -6,6 +6,7 @@ import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import info.nightscout.androidaps.extensions.PumpStateExtensionKt;
import org.joda.time.DateTime;
import org.json.JSONObject;
@ -96,7 +97,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
*/
private volatile boolean scripterIsBolusing;
/**
* This is set to true to request a bolus cancellation. {@link #deliverBolus(DetailedBolusInfo)}
* This is set to true to request a bolus cancellation. {@link #deliverTreatment(DetailedBolusInfo)} (DetailedBolusInfo)}
* will reset this flag.
*/
private volatile boolean cancelBolus;
@ -105,7 +106,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* This is set (in {@link #checkHistory()} whenever a connection to the pump is made and
* indicates if new history records on the pump have been found. This effectively blocks
* high temps ({@link #setTempBasalPercent(Integer, Integer, PumpSync.TemporaryBasalType)} and boluses
* ({@link #deliverBolus(DetailedBolusInfo)} till the queue is empty and the connection
* ({@link #deliverTreatment(DetailedBolusInfo)} till the queue is empty and the connection
* is shut down.
* {@link #initializePump()} resets this since on startup the history is allowed to have
* changed (and the user can't possible have already calculated anything with out of date IOB).
@ -120,7 +121,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
/**
* Cache of the last <=2 boluses on the pump. Used to detect changes in pump history,
* requiring reading more pump history. This is read/set in {@link #checkHistory()} when changed
* pump history was detected and was read, as well as in {@link #deliverBolus(DetailedBolusInfo)}
* pump history was detected and was read, as well as in {@link #deliverTreatment(DetailedBolusInfo)}
* after bolus delivery. Newest record is the first one.
*/
private volatile List<Bolus> recentBoluses = new ArrayList<>(0);
@ -474,41 +475,9 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
*/
@NonNull @Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
try {
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
// neither carbs nor bolus requested
getAapsLogger().error("deliverTreatment: Invalid input");
return new PumpEnactResult(getInjector()).success(false).enacted(false)
.bolusDelivered(0d).carbsDelivered(0d)
.comment(R.string.invalidinput);
// } else if (detailedBolusInfo.insulin > 0) {
} else {
// bolus needed, ask pump to deliver it
return deliverBolus(detailedBolusInfo);
}
/* This should not happen anymore
else {
// no bolus required, carb only treatment
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.setT(new EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB));
bolusingEvent.setPercent(100);
rxBus.send(bolusingEvent);
return new PumpEnactResult(getInjector()).success(true).enacted(true)
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
.comment(R.string.virtualpump_resultok);
}
*/
} finally {
rxBus.send(new EventComboPumpUpdateGUI());
if (detailedBolusInfo.insulin == 0 || detailedBolusInfo.carbs > 0) {
throw new IllegalArgumentException(detailedBolusInfo.toString());
}
}
@NonNull
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
try {
pump.activity = getResourceHelper().gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
rxBus.send(new EventComboPumpUpdateGUI());
@ -668,39 +637,18 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus.
*/
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
DetailedBolusInfo bolusInfo = detailedBolusInfo.copy();
bolusInfo.setBolusTimestamp(calculateFakeBolusDate(lastPumpBolus));
bolusInfo.setPumpType(PumpType.ACCU_CHEK_COMBO);
bolusInfo.setPumpSerial(serialNumber());
bolusInfo.setBolusPumpId(bolusInfo.timestamp);
bolusInfo.insulin = lastPumpBolus.amount;
try {
/* this should not happen
if (bolusInfo.carbs > 0 && bolusInfo.carbTime != 0) {
// split out a separate carbs record without a pumpId
DetailedBolusInfo carbInfo = new DetailedBolusInfo();
carbInfo.timestamp = bolusInfo.timestamp + bolusInfo.carbTime * 60L * 1000L;
carbInfo.carbs = bolusInfo.carbs;
carbInfo.setPumpType(PumpType.USER);
treatmentsPlugin.addToHistoryTreatment(carbInfo, true);
// remove carbs from bolusInfo to not trigger any unwanted code paths in
// TreatmentsPlugin.addToHistoryTreatment() method
bolusInfo.carbTime = 0;
bolusInfo.carbs = 0;
}
*/
pumpSync.syncBolusWithPumpId(
calculateFakeBolusDate(lastPumpBolus),
lastPumpBolus.timestamp,
lastPumpBolus.amount,
detailedBolusInfo.getBolusType(),
bolusInfo.timestamp,
generatePumpBolusId(lastPumpBolus),
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
} catch (Exception e) {
getAapsLogger().error("Adding treatment record failed", e);
if (bolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB) {
if (detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB) {
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, getResourceHelper().gs(R.string.combo_error_updating_treatment_record), Notification.URGENT);
rxBus.send(new EventNewNotification(notification));
}
@ -791,7 +739,12 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
T.mins(state.tbrRemainingDuration).msecs(),
false,
tbrType,
state.timestamp, // no pumpId available ????
// There are no IDs for TBRs on the pump and none is calculated (in contrast to boluses).
// The current time is used here as an ID, which has no meaning and does not allow identifying
// the record on the pump (which isn't needed), but only needs to be unique.
// Generally, TBR records are created when a TBR is set by AAPS or when a change on the pump has
// been detected, rather than checking the pumps history of TBRs.
state.timestamp,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
@ -820,9 +773,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
@NonNull @Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
getAapsLogger().debug(LTag.PUMP, "cancelTempBasal called");
//final TemporaryBasal activeTemp = treatmentsPlugin.getTempBasalFromHistoryIncludingConvertedExtended(System.currentTimeMillis());
PumpSync.PumpState pumpSate = pumpSync.expectedPumpState();
final PumpSync.PumpState.TemporaryBasal activeTemp = pumpSate.getTemporaryBasal();
final PumpSync.PumpState.TemporaryBasal activeTemp = pumpSync.expectedPumpState().getTemporaryBasal();
if (enforceNew) {
CommandResult stateResult = runCommand(getResourceHelper().gs(R.string.combo_pump_action_refreshing), 2, ruffyScripter::readPumpState);
if (!stateResult.success) {
@ -839,6 +790,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
if (!cancelResult.state.tbrActive) {
pumpSync.syncStopTemporaryBasalWithPumpId(
cancelResult.state.timestamp,
// Combo doesn't have nor uses IDs for TBRs, see note in #setTempBasalPercent
cancelResult.state.timestamp,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
@ -849,15 +801,16 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
}
} else if (activeTemp == null) {
return new PumpEnactResult(getInjector()).success(true).enacted(false);
} else if ((activeTemp.getRate() >= 90 && activeTemp.getRate() <= 110) && info.nightscout.androidaps.extensions.PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) <= 15) {
} else if ((activeTemp.getRate() >= 90 && activeTemp.getRate() <= 110)
&& PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) <= 15) {
// Let fake neutral temp keep run (see below)
// Note that since this runs on the queue a connection is opened regardless, but this
// case doesn't occur all that often, so it's not worth optimizing (1.3k SetTBR vs 4 cancelTBR).
getAapsLogger().debug(LTag.PUMP, "cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.getRate() + "% and running for another " + info.nightscout.androidaps.extensions.PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) + " mins.");
getAapsLogger().debug(LTag.PUMP, "cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.getRate() + "% and running for another " + PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) + " mins.");
return new PumpEnactResult(getInjector()).success(true).enacted(true)
.comment("cancelTempBasal skipping changing tbr since it already is at "
+ activeTemp.getRate() + "% and running for another "
+ info.nightscout.androidaps.extensions.PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) + " mins.");
+ PumpStateExtensionKt.getPlannedRemainingMinutes(activeTemp) + " mins.");
} else {
// Set a fake neutral temp to avoid TBR cancel alert. Decide 90% vs 110% based on
// on whether the TBR we're cancelling is above or below 100%.
@ -992,7 +945,8 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
T.mins(15).msecs(),
false,
PumpSync.TemporaryBasalType.PUMP_SUSPEND,
now, // no pumpId available ????
// Combo doesn't have nor uses IDs for TBRs, see note in #setTempBasalPercent
now,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
@ -1113,6 +1067,8 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
private void checkAndResolveTbrMismatch(PumpState state) {
// compare with: info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal.updateTempBasalInDB()
long now = System.currentTimeMillis();
// Combo doesn't have nor uses IDs for TBRs, see note in #setTempBasalPercent
long tbrId = now;
//TemporaryBasal aapsTbr = treatmentsPlugin.getTempBasalFromHistoryIncludingConvertedExtended(now);
PumpSync.PumpState.TemporaryBasal aapsTbr = pumpSync.expectedPumpState().getTemporaryBasal();
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
@ -1123,36 +1079,40 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
T.mins(state.tbrRemainingDuration).msecs(),
false,
PumpSync.TemporaryBasalType.NORMAL,
now, // no pumpId available ????
tbrId,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
} else if (aapsTbr != null && info.nightscout.androidaps.extensions.PumpStateExtensionKt.getPlannedRemainingMinutes(aapsTbr) > 2 && !state.tbrActive) {
} else if (aapsTbr != null && PumpStateExtensionKt.getPlannedRemainingMinutes(aapsTbr) > 2 && !state.tbrActive) {
getAapsLogger().debug(LTag.PUMP, "Ending AAPS-TBR since pump has no TBR active");
pumpSync.syncStopTemporaryBasalWithPumpId(
now,
now,
tbrId,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
} else if (aapsTbr != null && state.tbrActive
&& (aapsTbr.getRate() != state.tbrPercent ||
Math.abs(info.nightscout.androidaps.extensions.PumpStateExtensionKt.getPlannedRemainingMinutes(aapsTbr) - state.tbrRemainingDuration) > 2)) {
Math.abs(PumpStateExtensionKt.getPlannedRemainingMinutes(aapsTbr) - state.tbrRemainingDuration) > 2)) {
getAapsLogger().debug(LTag.PUMP, "AAPSs and pump-TBR differ; ending AAPS-TBR and creating new TBR based on pump TBR");
// crate TBR end record a second ago
pumpSync.syncStopTemporaryBasalWithPumpId(
now - 1000,
now - 1000,
// fake a unique ID that doesn't clash with the record below
tbrId - 1000,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
// Create TBR start record, starting now
pumpSync.syncTemporaryBasalWithPumpId(
now,
state.tbrPercent,
T.mins(state.tbrRemainingDuration).msecs(),
false,
PumpSync.TemporaryBasalType.NORMAL,
now, // no pumpId available ????
tbrId,
PumpType.ACCU_CHEK_COMBO,
serialNumber()
);
@ -1189,10 +1149,10 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
boolean updated = false;
for (Bolus pumpBolus : history.bolusHistory) {
if (pumpSync.syncBolusWithPumpId(
calculateFakeBolusDate(pumpBolus),
pumpBolus.timestamp,
pumpBolus.amount,
DetailedBolusInfo.BolusType.NORMAL,
System.currentTimeMillis(),
generatePumpBolusId(pumpBolus),
PumpType.ACCU_CHEK_COMBO,
serialNumber()
)) {
@ -1209,7 +1169,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* Should be good enough, even with command mode, it's a challenge to create that situation
* and most time clashes will be around SMBs which are covered.
*/
long calculateFakeBolusDate(Bolus pumpBolus) {
long generatePumpBolusId(Bolus pumpBolus) {
double bolus = pumpBolus.amount - 0.1;
int secondsFromBolus = (int) (bolus * 10 * 1000);
return pumpBolus.timestamp + Math.min(secondsFromBolus, 59 * 1000);

View file

@ -64,22 +64,22 @@ class ComboPluginTest : TestBase() {
}
@Test
fun calculateFakePumpTimestamp() {
fun `generate bolus ID from timestamp and amount`() {
val now = System.currentTimeMillis()
val pumpTimestamp = now - now % 1000
// same timestamp, different bolus leads to different fake timestamp
Assert.assertNotEquals(
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.1, true)),
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.3, true))
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.1, true)),
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true))
)
// different timestamp, same bolus leads to different fake timestamp
Assert.assertNotEquals(
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.3, true)),
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp + 60 * 1000, 0.3, true))
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true)),
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp + 60 * 1000, 0.3, true))
)
// generated timestamp has second-precision
val bolus = Bolus(pumpTimestamp, 0.2, true)
val calculatedTimestamp = comboPlugin.calculateFakeBolusDate(bolus)
val calculatedTimestamp = comboPlugin.generatePumpBolusId(bolus)
Assert.assertEquals(calculatedTimestamp, calculatedTimestamp - calculatedTimestamp % 1000)
}
}

View file

@ -10,6 +10,7 @@ interface ResourceHelper {
fun gs(@StringRes id: Int): String
fun gs(@StringRes id: Int, vararg args: Any?): String
fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String
fun gsNotLocalised(@StringRes id: Int, vararg args: Any?): String
fun gc(@ColorRes id: Int): Int
fun gd(@DrawableRes id: Int): Drawable?
fun gb(@BoolRes id :Int) : Boolean

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.utils.resources
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.AssetFileDescriptor
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
@ -10,6 +11,7 @@ import android.util.DisplayMetrics
import androidx.annotation.*
import androidx.core.content.ContextCompat
import info.nightscout.androidaps.core.R
import java.util.*
import javax.inject.Inject
/**
@ -24,6 +26,12 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont
override fun gq(@PluralsRes id: Int, quantity: Int, vararg args: Any?): String =
context.resources.getQuantityString(id, quantity, *args)
override fun gsNotLocalised(@StringRes id: Int, vararg args: Any?) : String =
with(Configuration(context.resources.configuration)) {
setLocale(Locale.ENGLISH)
context.createConfigurationContext(this).getString(id, args)
}
override fun gc(@ColorRes id: Int): Int = ContextCompat.getColor(context, id)
override fun gd(@DrawableRes id: Int): Drawable? = context.getDrawable(id)

View file

@ -119,7 +119,6 @@ class UserEntryPresentationHelper @Inject constructor(
is ValueWithUnit.UnitPerHour -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(valueWithUnit)
is ValueWithUnit.SimpleInt -> valueWithUnit.value.toString()
is ValueWithUnit.SimpleString -> valueWithUnit.value
is ValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value, *(valueWithUnit.params.map { it.value() }.toTypedArray()))
is ValueWithUnit.TherapyEventMeterType -> translator.translate(valueWithUnit.value)
is ValueWithUnit.TherapyEventTTReason -> translator.translate(valueWithUnit.value)
is ValueWithUnit.TherapyEventType -> translator.translate(valueWithUnit.value)
@ -182,9 +181,6 @@ class UserEntryPresentationHelper @Inject constructor(
var hour = ""
var minute = ""
var other = ""
for (valueWithUnit in entry.values) {
if (valueWithUnit is ValueWithUnit.StringResource) fullvalueWithUnitList.addAll(valueWithUnit.params)
}
for (valueWithUnit in fullvalueWithUnitList.filterNotNull()) {
when (valueWithUnit) {
@ -196,7 +192,6 @@ class UserEntryPresentationHelper @Inject constructor(
is ValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value)
is ValueWithUnit.SimpleInt -> other = other.addWithSeparator(valueWithUnit.value)
is ValueWithUnit.SimpleString -> other = other.addWithSeparator(valueWithUnit.value)
is ValueWithUnit.StringResource -> stringResource = stringResource.addWithSeparator(resourceHelper.gs(valueWithUnit.value, *(valueWithUnit.params.map { it.value() }.toTypedArray())))
is ValueWithUnit.TherapyEventMeterType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
is ValueWithUnit.TherapyEventTTReason -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
is ValueWithUnit.TherapyEventType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value))
@ -222,9 +217,9 @@ class UserEntryPresentationHelper @Inject constructor(
return "$timestampRec;$dateTimestampRev;$utcOffset;$action;$therapyEvent;$source;$note;$stringResource;$timestamp;$bg;$gram;$insulin;$unitPerHour;$percent;$hour;$minute;$other"
}
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"") + "\""
private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"") + "\"" else ""
private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"") + "\"" else ""
private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"").replace("\n"," / ") + "\""
private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"").replace("\n"," / ") + "\"" else ""
private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"").replace("\n"," / ") + "\"" else ""
private fun String.addWithSeparator(add: Any) =
this + (if (this.isBlank()) "" else " / ") + add.toString()

View file

@ -38,8 +38,6 @@ sealed class ValueWithUnitMapper { //I use a sealed class because of St
data class TherapyEventTTReason(val value: TemporaryTarget.Reason) : ValueWithUnitMapper()
data class StringResource(@StringRes val value: Int, val params: List<ValueWithUnitMapper> = listOf()) : ValueWithUnitMapper()
fun db(): ValueWithUnit? {
return when(this) {
is Gram -> ValueWithUnit.Gram(this.value)
@ -51,7 +49,6 @@ sealed class ValueWithUnitMapper { //I use a sealed class because of St
is Percent -> ValueWithUnit.Percent(this.value)
is SimpleInt -> ValueWithUnit.SimpleInt(this.value)
is SimpleString -> ValueWithUnit.SimpleString(this.value)
is StringResource -> ValueWithUnit.StringResource(this.value, this.params.map {it.db()}.filterNotNull())
is TherapyEventMeterType -> ValueWithUnit.TherapyEventMeterType(this.value)
is TherapyEventTTReason -> ValueWithUnit.TherapyEventTTReason(this.value)
is TherapyEventType -> ValueWithUnit.TherapyEventType(this.value)
@ -72,7 +69,6 @@ sealed class ValueWithUnitMapper { //I use a sealed class because of St
is Percent -> this.value
is SimpleInt -> this.value
is SimpleString -> this.value
is StringResource -> this.value
is TherapyEventMeterType -> this.value
is TherapyEventTTReason -> this.value
is TherapyEventType -> this.value

View file

@ -34,8 +34,6 @@ sealed class ValueWithUnit {
data class TherapyEventTTReason(val value: TemporaryTarget.Reason) : ValueWithUnit()
data class StringResource(@StringRes val value: Int, val params: List<ValueWithUnit> = listOf()) : ValueWithUnit()
fun value(): Any? {
return when(this) {
is Gram -> this.value
@ -47,7 +45,6 @@ sealed class ValueWithUnit {
is Percent -> this.value
is SimpleInt -> this.value
is SimpleString -> this.value
is StringResource -> this.value
is TherapyEventMeterType -> this.value
is TherapyEventTTReason -> this.value
is TherapyEventType -> this.value