Clean up initial profile push to pump.
This commit is contained in:
parent
259b5fa818
commit
52c6d209af
|
@ -741,22 +741,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
profileSwitch.timeshift = timeshift;
|
||||
profileSwitch.percentage = percentage;
|
||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||
|
||||
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
MainApp.bus().post(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||
}
|
||||
|
||||
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
||||
|
@ -773,22 +757,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
profileSwitch.timeshift = timeshift;
|
||||
profileSwitch.percentage = percentage;
|
||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||
|
||||
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
MainApp.bus().post(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||
} else {
|
||||
log.error("No profile switch existing");
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -33,6 +35,8 @@ import info.nightscout.androidaps.db.TempTarget;
|
|||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppInitialized;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
|
@ -44,11 +48,13 @@ import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
|||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.queue.CommandQueue;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
import info.nightscout.utils.FabricPrivacy;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -643,6 +649,28 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
|
|||
NSUpload.uploadProfileSwitch(profileSwitch);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProfileSwitch(EventProfileSwitchChange ignored) {
|
||||
if (getCommandQueue().isRunning(Command.CommandType.BASALPROFILE))
|
||||
return;
|
||||
|
||||
getCommandQueue().setProfile(getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
MainApp.bus().post(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long oldestDataAvailable() {
|
||||
return activeTreatments.oldestDataAvailable();
|
||||
|
|
|
@ -84,7 +84,7 @@ public class CommandQueue {
|
|||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.sResources.getString(R.string.executingrightnow));
|
||||
}
|
||||
|
||||
private boolean isRunning(Command.CommandType type) {
|
||||
public boolean isRunning(Command.CommandType type) {
|
||||
if (performing != null && performing.commandType == type)
|
||||
return true;
|
||||
return false;
|
||||
|
@ -296,21 +296,6 @@ public class CommandQueue {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check that there is a valid profileSwitch NOW
|
||||
if (MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis())==null) {
|
||||
// wait for DatabaseHelper.scheduleProfiSwitch() to do the profile switch // TODO clean this crap up
|
||||
SystemClock.sleep(5000);
|
||||
if (MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis())==null) {
|
||||
Notification noProfileSwitchNotif = new Notification(Notification.PROFILE_SWITCH_MISSING, MainApp.gs(R.string.profileswitch_ismissing), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(noProfileSwitchNotif));
|
||||
if (callback != null) {
|
||||
PumpEnactResult result = new PumpEnactResult().success(false).enacted(false).comment("Refuse to send profile to pump! No ProfileSwitch!");
|
||||
callback.result(result).run();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MainApp.isEngineeringModeOrRelease()) {
|
||||
Notification notification = new Notification(Notification.NOT_ENG_MODE_OR_RELEASE, MainApp.sResources.getString(R.string.not_eng_mode_or_release), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Date;
|
|||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
|
@ -60,11 +61,11 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
LocalAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated);
|
||||
|
||||
if (!pump.isThisProfileSet(profile)) {
|
||||
MainApp.getConfigBuilder().getCommandQueue().setProfile(profile, null);
|
||||
MainApp.bus().post(new EventProfileSwitchChange());
|
||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||
ConfigBuilderPlugin.getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||
} else if (isBasalOutdated && !pump.isBusy()) {
|
||||
MainApp.getConfigBuilder().getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
|
||||
ConfigBuilderPlugin.getCommandQueue().readStatus("KeepAlive. Basal outdated.", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,18 +88,17 @@ public class CommandQueueTest extends CommandQueue {
|
|||
extendedBolus(1, 30, null);
|
||||
Assert.assertEquals(2, size());
|
||||
|
||||
// add setProfile (command is not queued before unless a ProfileSwitch exists)
|
||||
// TODO test with profile switch set
|
||||
// add setProfile
|
||||
setProfile(profile, null);
|
||||
Assert.assertEquals(2, size());
|
||||
Assert.assertEquals(3, size());
|
||||
|
||||
// add loadHistory
|
||||
loadHistory((byte) 0, null);
|
||||
Assert.assertEquals(3, size());
|
||||
Assert.assertEquals(4, size());
|
||||
|
||||
// add loadEvents
|
||||
loadEvents(null);
|
||||
Assert.assertEquals(4, size());
|
||||
Assert.assertEquals(5, size());
|
||||
|
||||
clear();
|
||||
tempBasalAbsolute(0, 30, true, profile, null);
|
||||
|
|
Loading…
Reference in a new issue