Merge branch 'dev' into feature/728_wearos_complication
This commit is contained in:
commit
1240deb4d3
|
@ -129,7 +129,14 @@ public class MainApp extends Application {
|
||||||
sConstraintsChecker = new ConstraintChecker();
|
sConstraintsChecker = new ConstraintChecker();
|
||||||
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> log.error("Uncaught exception crashing app", ex));
|
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> {
|
||||||
|
if (ex instanceof InternalError) {
|
||||||
|
// usually the app trying to spawn a thread while being killed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.error("Uncaught exception crashing app", ex);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (FabricPrivacy.fabricEnabled()) {
|
if (FabricPrivacy.fabricEnabled()) {
|
||||||
|
|
|
@ -247,7 +247,7 @@ public class APSResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ public class APSResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return latest;
|
return latest;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
|
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
@ -75,35 +76,42 @@ public class ProfileFunctions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
return getProfileName(System.currentTimeMillis());
|
return getProfileName(System.currentTimeMillis(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName(boolean customized) {
|
public String getProfileName(boolean customized) {
|
||||||
return getProfileName(System.currentTimeMillis(), customized);
|
return getProfileName(System.currentTimeMillis(), customized, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName(long time) {
|
public String getProfileNameWithDuration() {
|
||||||
return getProfileName(time, true);
|
return getProfileName(System.currentTimeMillis(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName(long time, boolean customized) {
|
public String getProfileName(long time, boolean customized, boolean showRemainingTime) {
|
||||||
|
String profileName = MainApp.gs(R.string.noprofileselected);
|
||||||
|
|
||||||
TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin();
|
TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin();
|
||||||
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
||||||
|
|
||||||
ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time);
|
ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time);
|
||||||
if (profileSwitch != null) {
|
if (profileSwitch != null) {
|
||||||
if (profileSwitch.profileJson != null) {
|
if (profileSwitch.profileJson != null) {
|
||||||
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
|
profileName = customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
|
||||||
} else {
|
} else {
|
||||||
ProfileStore profileStore = activeProfile.getProfile();
|
ProfileStore profileStore = activeProfile.getProfile();
|
||||||
if (profileStore != null) {
|
if (profileStore != null) {
|
||||||
Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName);
|
Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName);
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
return profileSwitch.profileName;
|
profileName = profileSwitch.profileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showRemainingTime && profileSwitch.durationInMinutes != 0) {
|
||||||
|
profileName += DateUtil.untilString(profileSwitch.originalEnd());
|
||||||
|
}
|
||||||
|
return profileName;
|
||||||
}
|
}
|
||||||
return MainApp.gs(R.string.noprofileselected);
|
return profileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileValid(String from) {
|
public boolean isProfileValid(String from) {
|
||||||
|
@ -176,7 +184,7 @@ public class ProfileFunctions {
|
||||||
profileSwitch = new ProfileSwitch();
|
profileSwitch = new ProfileSwitch();
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
profileSwitch.source = Source.USER;
|
profileSwitch.source = Source.USER;
|
||||||
profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false);
|
profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false, false);
|
||||||
profileSwitch.profileJson = getInstance().getProfile().getData().toString();
|
profileSwitch.profileJson = getInstance().getProfile().getData().toString();
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
||||||
profileSwitch.durationInMinutes = duration;
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
|
|
@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
|
||||||
|
|
||||||
public class DstHelperPlugin extends PluginBase implements ConstraintsInterface {
|
public class DstHelperPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
public static final int DISABLE_TIMEFRAME_HOURS = -3;
|
public static final int DISABLE_TIMEFRAME_HOURS = -3;
|
||||||
public static final int WARN_PRIOR_TIMEFRAME_HOURS = 24;
|
public static final int WARN_PRIOR_TIMEFRAME_HOURS = 12;
|
||||||
private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
|
private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
|
||||||
|
|
||||||
static DstHelperPlugin plugin = null;
|
static DstHelperPlugin plugin = null;
|
||||||
|
|
|
@ -204,7 +204,7 @@ class ObjectivesFragment : Fragment() {
|
||||||
holder.accomplished.setTextColor(-0x3e3e3f)
|
holder.accomplished.setTextColor(-0x3e3e3f)
|
||||||
holder.verify.setOnClickListener {
|
holder.verify.setOnClickListener {
|
||||||
holder.verify.visibility = View.INVISIBLE
|
holder.verify.visibility = View.INVISIBLE
|
||||||
NetworkChangeReceiver.fetch()
|
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.accomplishedOn = DateUtil.now()
|
objective.accomplishedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
|
@ -236,7 +236,7 @@ class ObjectivesFragment : Fragment() {
|
||||||
}
|
}
|
||||||
holder.start.setOnClickListener {
|
holder.start.setOnClickListener {
|
||||||
holder.start.visibility = View.INVISIBLE
|
holder.start.visibility = View.INVISIBLE
|
||||||
NetworkChangeReceiver.fetch()
|
NetworkChangeReceiver.grabNetworkStatus(context)
|
||||||
if (objectives_fake.isChecked) {
|
if (objectives_fake.isChecked) {
|
||||||
objective.startedOn = DateUtil.now()
|
objective.startedOn = DateUtil.now()
|
||||||
scrollToCurrentObjective()
|
scrollToCurrentObjective()
|
||||||
|
|
|
@ -10,8 +10,11 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.Action;
|
import info.nightscout.androidaps.plugins.general.automation.actions.Action;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class AutomationEvent {
|
public class AutomationEvent {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(AutomationEvent.class);
|
||||||
|
|
||||||
private Trigger trigger = new TriggerConnector();
|
private Trigger trigger = new TriggerConnector();
|
||||||
private List<Action> actions = new ArrayList<>();
|
private List<Action> actions = new ArrayList<>();
|
||||||
|
@ -74,7 +77,7 @@ public class AutomationEvent {
|
||||||
}
|
}
|
||||||
o.put("actions", array);
|
o.put("actions", array);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +94,7 @@ public class AutomationEvent {
|
||||||
actions.add(Action.instantiate(new JSONObject(array.getString(i))));
|
actions.add(Action.instantiate(new JSONObject(array.getString(i))));
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Action ideas:
|
Action ideas:
|
||||||
|
@ -44,6 +46,7 @@ import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Action.class);
|
||||||
|
|
||||||
public Trigger precondition = null;
|
public Trigger precondition = null;
|
||||||
|
|
||||||
|
@ -65,7 +68,7 @@ public abstract class Action {
|
||||||
try {
|
try {
|
||||||
o.put("type", this.getClass().getName());
|
o.put("type", this.getClass().getName());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +87,7 @@ public abstract class Action {
|
||||||
Class clazz = Class.forName(type);
|
Class clazz = Class.forName(type);
|
||||||
return ((Action) clazz.newInstance()).fromJSON(data != null ? data.toString() : "");
|
return ((Action) clazz.newInstance()).fromJSON(data != null ? data.toString() : "");
|
||||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +101,7 @@ public abstract class Action {
|
||||||
fromJSON(data.toString());
|
fromJSON(data.toString());
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,12 @@ import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithE
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ActionLoopSuspend extends Action {
|
public class ActionLoopSuspend extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionLoopSuspend.class);
|
||||||
|
|
||||||
public InputDuration minutes = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
public InputDuration minutes = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +63,7 @@ public class ActionLoopSuspend extends Action {
|
||||||
o.put("type", this.getClass().getName());
|
o.put("type", this.getClass().getName());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +74,7 @@ public class ActionLoopSuspend extends Action {
|
||||||
JSONObject o = new JSONObject(data);
|
JSONObject o = new JSONObject(data);
|
||||||
minutes.setMinutes(JsonHelper.safeGetInt(o, "minutes"));
|
minutes.setMinutes(JsonHelper.safeGetInt(o, "minutes"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,12 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ActionNotification extends Action {
|
public class ActionNotification extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionNotification.class);
|
||||||
|
|
||||||
public InputString text = new InputString();
|
public InputString text = new InputString();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +63,7 @@ public class ActionNotification extends Action {
|
||||||
o.put("type", this.getClass().getName());
|
o.put("type", this.getClass().getName());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +74,7 @@ public class ActionNotification extends Action {
|
||||||
JSONObject o = new JSONObject(data);
|
JSONObject o = new JSONObject(data);
|
||||||
text.setValue(JsonHelper.safeGetString(o, "text"));
|
text.setValue(JsonHelper.safeGetString(o, "text"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class ActionProfileSwitch extends Action {
|
||||||
data.put("profileToSwitchTo", inputProfileName.getValue());
|
data.put("profileToSwitchTo", inputProfileName.getValue());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public class ActionProfileSwitch extends Action {
|
||||||
profileName = JsonHelper.safeGetString(d, "profileToSwitchTo");
|
profileName = JsonHelper.safeGetString(d, "profileToSwitchTo");
|
||||||
inputProfileName.setValue(profileName);
|
inputProfileName.setValue(profileName);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,12 @@ import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuil
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerProfilePercent;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerProfilePercent;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ActionProfileSwitchPercent extends Action {
|
public class ActionProfileSwitchPercent extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionProfileSwitchPercent.class);
|
||||||
|
|
||||||
InputPercent pct = new InputPercent();
|
InputPercent pct = new InputPercent();
|
||||||
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
@ -71,7 +75,7 @@ public class ActionProfileSwitchPercent extends Action {
|
||||||
data.put("durationInMinutes", duration.getMinutes());
|
data.put("durationInMinutes", duration.getMinutes());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +87,7 @@ public class ActionProfileSwitchPercent extends Action {
|
||||||
pct.setValue(JsonHelper.safeGetInt(d, "percentage"));
|
pct.setValue(JsonHelper.safeGetInt(d, "percentage"));
|
||||||
duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes"));
|
duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
|
||||||
public class ActionSendSMS extends Action {
|
public class ActionSendSMS extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionSendSMS.class);
|
||||||
|
|
||||||
public InputString text = new InputString();
|
public InputString text = new InputString();
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ public class ActionSendSMS extends Action {
|
||||||
o.put("type", this.getClass().getName());
|
o.put("type", this.getClass().getName());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -67,7 +68,7 @@ public class ActionSendSMS extends Action {
|
||||||
JSONObject o = new JSONObject(data);
|
JSONObject o = new JSONObject(data);
|
||||||
text.setValue(JsonHelper.safeGetString(o, "text"));
|
text.setValue(JsonHelper.safeGetString(o, "text"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,12 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ActionStartTempTarget extends Action {
|
public class ActionStartTempTarget extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionStartTempTarget.class);
|
||||||
|
|
||||||
String reason = "";
|
String reason = "";
|
||||||
InputTempTarget value = new InputTempTarget();
|
InputTempTarget value = new InputTempTarget();
|
||||||
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
@ -93,7 +97,7 @@ public class ActionStartTempTarget extends Action {
|
||||||
data.put("durationInMinutes", duration.getMinutes());
|
data.put("durationInMinutes", duration.getMinutes());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -107,7 +111,7 @@ public class ActionStartTempTarget extends Action {
|
||||||
value.setValue(JsonHelper.safeGetDouble(d, "value"));
|
value.setValue(JsonHelper.safeGetDouble(d, "value"));
|
||||||
duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes"));
|
duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,12 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ActionStopTempTarget extends Action {
|
public class ActionStopTempTarget extends Action {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ActionStopTempTarget.class);
|
||||||
|
|
||||||
String reason = "";
|
String reason = "";
|
||||||
private TempTarget tempTarget;
|
private TempTarget tempTarget;
|
||||||
|
|
||||||
|
@ -54,7 +58,7 @@ public class ActionStopTempTarget extends Action {
|
||||||
data.put("reason", reason);
|
data.put("reason", reason);
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +69,7 @@ public class ActionStopTempTarget extends Action {
|
||||||
JSONObject d = new JSONObject(data);
|
JSONObject d = new JSONObject(data);
|
||||||
reason = JsonHelper.safeGetString(d, "reason");
|
reason = JsonHelper.safeGetString(d, "reason");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,13 @@ import com.google.common.base.Optional;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class Trigger {
|
public abstract class Trigger {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Trigger.class);
|
||||||
|
|
||||||
TriggerConnector connector = null;
|
TriggerConnector connector = null;
|
||||||
long lastRun;
|
long lastRun;
|
||||||
|
@ -56,7 +59,7 @@ public abstract class Trigger {
|
||||||
try {
|
try {
|
||||||
return instantiate(new JSONObject(json));
|
return instantiate(new JSONObject(json));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +72,7 @@ public abstract class Trigger {
|
||||||
Class clazz = Class.forName(type);
|
Class clazz = Class.forName(type);
|
||||||
return ((Trigger) clazz.newInstance()).fromJSON(data.toString());
|
return ((Trigger) clazz.newInstance()).fromJSON(data.toString());
|
||||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class TriggerAutosensValue extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public class TriggerAutosensValue extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class TriggerBg extends Trigger {
|
||||||
data.put("units", bg.getUnits());
|
data.put("units", bg.getUnits());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ public class TriggerBg extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class TriggerBolusAgo extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class TriggerBolusAgo extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class TriggerCOB extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class TriggerCOB extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class TriggerConnector extends Trigger {
|
||||||
data.put("triggerList", array);
|
data.put("triggerList", array);
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class TriggerConnector extends Trigger {
|
||||||
add(newItem);
|
add(newItem);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class TriggerDelta extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public class TriggerDelta extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class TriggerIob extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class TriggerIob extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class TriggerLocation extends Trigger {
|
||||||
data.put("lastRun", lastRun);
|
data.put("lastRun", lastRun);
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class TriggerLocation extends Trigger {
|
||||||
name.setValue(JsonHelper.safeGetString(d, "name"));
|
name.setValue(JsonHelper.safeGetString(d, "name"));
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class TriggerProfilePercent extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class TriggerProfilePercent extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class TriggerPumpLastConnection extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class TriggerPumpLastConnection extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class TriggerRecurringTime extends Trigger {
|
||||||
object.put("type", TriggerRecurringTime.class.getName());
|
object.put("type", TriggerRecurringTime.class.getName());
|
||||||
object.put("data", data);
|
object.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return object.toString();
|
return object.toString();
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ public class TriggerRecurringTime extends Trigger {
|
||||||
minute = JsonHelper.safeGetInt(o, "minute");
|
minute = JsonHelper.safeGetInt(o, "minute");
|
||||||
validTo = JsonHelper.safeGetLong(o, "validTo");
|
validTo = JsonHelper.safeGetLong(o, "validTo");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class TriggerTempTarget extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class TriggerTempTarget extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(ComparatorExists.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(ComparatorExists.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class TriggerTime extends Trigger {
|
||||||
object.put("type", TriggerTime.class.getName());
|
object.put("type", TriggerTime.class.getName());
|
||||||
object.put("data", data);
|
object.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return object.toString();
|
return object.toString();
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public class TriggerTime extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(o, "lastRun");
|
lastRun = JsonHelper.safeGetLong(o, "lastRun");
|
||||||
runAt = JsonHelper.safeGetLong(o, "runAt");
|
runAt = JsonHelper.safeGetLong(o, "runAt");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class TriggerTimeRange extends Trigger {
|
||||||
object.put("type", TriggerTimeRange.class.getName());
|
object.put("type", TriggerTimeRange.class.getName());
|
||||||
object.put("data", data);
|
object.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
log.debug(object.toString());
|
log.debug(object.toString());
|
||||||
return object.toString();
|
return object.toString();
|
||||||
|
@ -108,7 +108,7 @@ public class TriggerTimeRange extends Trigger {
|
||||||
start = JsonHelper.safeGetInt(o, "start");
|
start = JsonHelper.safeGetInt(o, "start");
|
||||||
end = JsonHelper.safeGetInt(o, "end");
|
end = JsonHelper.safeGetInt(o, "end");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class TriggerWifiSsid extends Trigger {
|
||||||
data.put("comparator", comparator.getValue().toString());
|
data.put("comparator", comparator.getValue().toString());
|
||||||
o.put("data", data);
|
o.put("data", data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class TriggerWifiSsid extends Trigger {
|
||||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
nsClientReceiverDelegate =
|
nsClientReceiverDelegate =
|
||||||
new NsClientReceiverDelegate(MainApp.instance().getApplicationContext());
|
new NsClientReceiverDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed() {
|
public boolean isAllowed() {
|
||||||
|
@ -104,7 +104,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
nsClientReceiverDelegate.registerReceivers();
|
nsClientReceiverDelegate.grabReceiversState();
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventNSClientStatus.class)
|
.toObservable(EventNSClientStatus.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -129,7 +129,6 @@ public class NSClientPlugin extends PluginBase {
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
if (nsClientService != null) {
|
if (nsClientService != null) {
|
||||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||||
nsClientReceiverDelegate.unregisterReceivers();
|
|
||||||
}
|
}
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
@ -152,7 +151,6 @@ public class NSClientPlugin extends PluginBase {
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||||
nsClientReceiverDelegate.unregisterReceivers();
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -594,7 +594,7 @@ public class NSUpload {
|
||||||
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,44 +18,19 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
class NsClientReceiverDelegate {
|
class NsClientReceiverDelegate {
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
|
|
||||||
private NetworkChangeReceiver networkChangeReceiver = new NetworkChangeReceiver();
|
|
||||||
private ChargingStateReceiver chargingStateReceiver = new ChargingStateReceiver();
|
|
||||||
|
|
||||||
private boolean allowedChargingState = true;
|
private boolean allowedChargingState = true;
|
||||||
private boolean allowedNetworkState = true;
|
private boolean allowedNetworkState = true;
|
||||||
boolean allowed = true;
|
boolean allowed = true;
|
||||||
|
|
||||||
NsClientReceiverDelegate(Context context) {
|
void grabReceiversState() {
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerReceivers() {
|
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
// register NetworkChangeReceiver --> https://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
|
|
||||||
// Nougat is not providing Connectivity-Action anymore ;-(
|
|
||||||
context.registerReceiver(networkChangeReceiver,
|
|
||||||
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
|
||||||
context.registerReceiver(networkChangeReceiver,
|
|
||||||
new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
|
|
||||||
|
|
||||||
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(context);
|
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(context);
|
||||||
if (event != null)
|
if (event != null) RxBus.INSTANCE.send(event);
|
||||||
RxBus.INSTANCE.send(event);
|
|
||||||
|
|
||||||
context.registerReceiver(chargingStateReceiver,
|
EventChargingState eventChargingState = ChargingStateReceiver.grabChargingState(context);
|
||||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
if (eventChargingState != null) RxBus.INSTANCE.send(eventChargingState);
|
||||||
|
|
||||||
EventChargingState eventChargingState = chargingStateReceiver.grabChargingState(context);
|
|
||||||
if (eventChargingState != null)
|
|
||||||
RxBus.INSTANCE.send(eventChargingState);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void unregisterReceivers() {
|
|
||||||
context.unregisterReceiver(networkChangeReceiver);
|
|
||||||
context.unregisterReceiver(chargingStateReceiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStatusEvent(EventPreferenceChange ev) {
|
void onStatusEvent(EventPreferenceChange ev) {
|
||||||
|
@ -63,11 +38,11 @@ class NsClientReceiverDelegate {
|
||||||
ev.isChanged(R.string.key_ns_wifi_ssids) ||
|
ev.isChanged(R.string.key_ns_wifi_ssids) ||
|
||||||
ev.isChanged(R.string.key_ns_allowroaming)
|
ev.isChanged(R.string.key_ns_allowroaming)
|
||||||
) {
|
) {
|
||||||
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
||||||
if (event != null)
|
if (event != null)
|
||||||
RxBus.INSTANCE.send(event);
|
RxBus.INSTANCE.send(event);
|
||||||
} else if (ev.isChanged(R.string.key_ns_chargingonly)) {
|
} else if (ev.isChanged(R.string.key_ns_chargingonly)) {
|
||||||
EventChargingState event = chargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
EventChargingState event = ChargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
||||||
if (event != null)
|
if (event != null)
|
||||||
RxBus.INSTANCE.send(event);
|
RxBus.INSTANCE.send(event);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +66,7 @@ class NsClientReceiverDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processStateChange() {
|
private void processStateChange() {
|
||||||
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
||||||
if (newAllowedState != allowed) {
|
if (newAllowedState != allowed) {
|
||||||
allowed = newAllowedState;
|
allowed = newAllowedState;
|
||||||
|
@ -101,7 +76,6 @@ class NsClientReceiverDelegate {
|
||||||
|
|
||||||
boolean calculateStatus(final EventChargingState ev) {
|
boolean calculateStatus(final EventChargingState ev) {
|
||||||
boolean chargingOnly = SP.getBoolean(R.string.key_ns_chargingonly, false);
|
boolean chargingOnly = SP.getBoolean(R.string.key_ns_chargingonly, false);
|
||||||
|
|
||||||
boolean newAllowedState = true;
|
boolean newAllowedState = true;
|
||||||
|
|
||||||
if (!ev.isCharging() && chargingOnly) {
|
if (!ev.isCharging() && chargingOnly) {
|
||||||
|
@ -129,8 +103,6 @@ class NsClientReceiverDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return newAllowedState;
|
return newAllowedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1223,7 +1223,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
extendedBolusView.setVisibility(View.VISIBLE);
|
extendedBolusView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
activeProfileView.setText(ProfileFunctions.getInstance().getProfileName());
|
activeProfileView.setText(ProfileFunctions.getInstance().getProfileNameWithDuration());
|
||||||
if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) {
|
if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) {
|
||||||
activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
|
activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
|
||||||
activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
|
activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
|
||||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Encoding4b6bLoop extends Encoding4b6bAbstract {
|
public class Encoding4b6bLoop extends Encoding4b6bAbstract {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Encoding4b6bLoop.class);
|
||||||
|
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(Encoding4b6bLoop.class);
|
public static final Logger LOG = LoggerFactory.getLogger(Encoding4b6bLoop.class);
|
||||||
public Map<Integer, Byte> codesRev = null;
|
public Map<Integer, Byte> codesRev = null;
|
||||||
|
@ -108,9 +109,8 @@ public class Encoding4b6bLoop extends Encoding4b6bAbstract {
|
||||||
int index2 = ((bitAccumulator >> (availBits - 12)) & 0b111111);
|
int index2 = ((bitAccumulator >> (availBits - 12)) & 0b111111);
|
||||||
hiNibble = codesRev.get((bitAccumulator >> (availBits - 6)));
|
hiNibble = codesRev.get((bitAccumulator >> (availBits - 6)));
|
||||||
loNibble = codesRev.get(((bitAccumulator >> (availBits - 12)) & 0b111111));
|
loNibble = codesRev.get(((bitAccumulator >> (availBits - 12)) & 0b111111));
|
||||||
} catch (Exception ex) {
|
} catch (Exception e) {
|
||||||
System.out.println("Exception: " + ex.getMessage());
|
log.error("Unhandled exception", e);
|
||||||
ex.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
try {
|
try {
|
||||||
o.wait();
|
o.wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,11 +4,15 @@ import android.annotation.TargetApi;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.cozmo.danar.util.BleCommandUtil;
|
import com.cozmo.danar.util.BleCommandUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class DanaRS_Packet {
|
public class DanaRS_Packet {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DanaRS_Packet.class);
|
||||||
|
|
||||||
protected static final int TYPE_START = 0;
|
protected static final int TYPE_START = 0;
|
||||||
protected static final int OPCODE_START = 1;
|
protected static final int OPCODE_START = 1;
|
||||||
protected static final int DATA_START = 2;
|
protected static final int DATA_START = 2;
|
||||||
|
@ -73,7 +77,7 @@ public class DanaRS_Packet {
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -551,7 +551,7 @@ public class BLEComm {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
startSignatureFound = false;
|
startSignatureFound = false;
|
||||||
packetIsValid = false;
|
packetIsValid = false;
|
||||||
|
@ -635,7 +635,7 @@ public class BLEComm {
|
||||||
message.wait(5000);
|
message.wait(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.error("sendMessage InterruptedException", e);
|
log.error("sendMessage InterruptedException", e);
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1526,7 +1526,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
data.put("notes", note);
|
data.put("notes", note);
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1554,7 +1554,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
data.put("eventType", event);
|
data.put("eventType", event);
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,11 @@ package info.nightscout.androidaps.plugins.pump.insight.app_layer.history.histor
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryEventIDs;
|
import info.nightscout.androidaps.plugins.pump.insight.ids.HistoryEventIDs;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.BOCUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ByteBuf;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class HistoryEvent implements Comparable<HistoryEvent> {
|
public class HistoryEvent implements Comparable<HistoryEvent> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HistoryEvent.class);
|
||||||
|
|
||||||
private int eventYear;
|
private int eventYear;
|
||||||
private int eventMonth;
|
private int eventMonth;
|
||||||
|
@ -22,10 +25,8 @@ public class HistoryEvent implements Comparable<HistoryEvent> {
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
event = eventClass.newInstance();
|
event = eventClass.newInstance();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.parseHeader(byteBuf);
|
event.parseHeader(byteBuf);
|
||||||
|
|
|
@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperAc
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
|
@ -372,7 +373,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
refreshAnyStatusThatNeedsToBeRefreshed();
|
refreshAnyStatusThatNeedsToBeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged());
|
RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -386,7 +387,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
|
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
|
||||||
|
|
||||||
if (rileyLinkServiceState==null) {
|
if (rileyLinkServiceState == null) {
|
||||||
LOG.error("RileyLink unreachable. RileyLinkServiceState is null.");
|
LOG.error("RileyLink unreachable. RileyLinkServiceState is null.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -744,13 +745,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
ClockDTO clock = MedtronicUtil.getPumpTime();
|
ClockDTO clock = MedtronicUtil.getPumpTime();
|
||||||
|
|
||||||
if (clock==null) { // retry
|
if (clock == null) { // retry
|
||||||
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
|
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
|
||||||
|
|
||||||
clock = MedtronicUtil.getPumpTime();
|
clock = MedtronicUtil.getPumpTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clock==null)
|
if (clock == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int timeDiff = Math.abs(clock.timeDifference);
|
int timeDiff = Math.abs(clock.timeDifference);
|
||||||
|
@ -866,6 +867,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
detailedBolusInfo.date = now;
|
||||||
|
detailedBolusInfo.deliverAt = now; // not sure about that one
|
||||||
|
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||||
|
@ -877,7 +883,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
// calculate time for bolus and set driver to busy for that time
|
// calculate time for bolus and set driver to busy for that time
|
||||||
int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d);
|
int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d);
|
||||||
long time = System.currentTimeMillis() + (bolusTime * 1000);
|
long time = now + (bolusTime * 1000);
|
||||||
|
|
||||||
this.busyTimestamps.add(time);
|
this.busyTimestamps.add(time);
|
||||||
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
|
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
|
||||||
|
@ -1065,10 +1071,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
||||||
boolean enforceNew) {
|
boolean enforceNew) {
|
||||||
if (percent==0) {
|
if (percent == 0) {
|
||||||
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
|
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
|
||||||
} else {
|
} else {
|
||||||
double absoluteValue = profile.getBasal() * (percent /100.0d);
|
double absoluteValue = profile.getBasal() * (percent / 100.0d);
|
||||||
getMDTPumpStatus();
|
getMDTPumpStatus();
|
||||||
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
|
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
|
||||||
LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue);
|
LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue);
|
||||||
|
|
|
@ -412,25 +412,18 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
||||||
rate = body[1] * 0.025f;
|
rate = body[1] * 0.025f;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index,
|
//LOG.info("Basal Profile Start: offset={}, rate={}, index={}, body_raw={}", offset, rate, index, body);
|
||||||
body);
|
|
||||||
|
|
||||||
if (rate == null) {
|
if (rate == null) {
|
||||||
LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index,
|
LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index,
|
||||||
body);
|
body);
|
||||||
return RecordDecodeStatus.Error;
|
return RecordDecodeStatus.Error;
|
||||||
} else {
|
} else {
|
||||||
// writeData(PumpBaseType.Basal, PumpBasalType.ValueChange, getFormattedFloat(rate, 3),
|
|
||||||
// entry.getATechDate());
|
|
||||||
entry.addDecodedData("Value", getFormattedFloat(rate, 3));
|
entry.addDecodedData("Value", getFormattedFloat(rate, 3));
|
||||||
entry.setDisplayableValue(getFormattedFloat(rate, 3));
|
entry.setDisplayableValue(getFormattedFloat(rate, 3));
|
||||||
return RecordDecodeStatus.OK;
|
return RecordDecodeStatus.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// profileIndex = asUINT8(data[1]);
|
|
||||||
// offset = asUINT8(data[7]) * 30 * 1000 * 60;
|
|
||||||
// rate = (double)(asUINT8(data[8])) / 40.0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,10 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by andy on 9/23/18.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* History page contains data, sorted from newest to oldest (0=newest..n=oldest)
|
* History page contains data, sorted from newest to oldest (0=newest..n=oldest)
|
||||||
|
*
|
||||||
|
* Created by andy on 9/23/18.
|
||||||
*/
|
*/
|
||||||
public class PumpHistoryResult {
|
public class PumpHistoryResult {
|
||||||
|
|
||||||
|
@ -29,8 +27,6 @@ public class PumpHistoryResult {
|
||||||
public List<PumpHistoryEntry> validEntries;
|
public List<PumpHistoryEntry> validEntries;
|
||||||
|
|
||||||
|
|
||||||
// private Object validValues;
|
|
||||||
|
|
||||||
public PumpHistoryResult(PumpHistoryEntry searchEntry, Long targetDate) {
|
public PumpHistoryResult(PumpHistoryEntry searchEntry, Long targetDate) {
|
||||||
if (searchEntry != null) {
|
if (searchEntry != null) {
|
||||||
/*
|
/*
|
||||||
|
@ -109,9 +105,8 @@ public class PumpHistoryResult {
|
||||||
if (unprocessedEntry.isAfter(this.searchDate)) {
|
if (unprocessedEntry.isAfter(this.searchDate)) {
|
||||||
this.validEntries.add(unprocessedEntry);
|
this.validEntries.add(unprocessedEntry);
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("PE. PumpHistoryResult. Not after.. Unprocessed Entry [year={},entry={}]",
|
// LOG.debug("PE. PumpHistoryResult. Not after.. Unprocessed Entry [year={},entry={}]",
|
||||||
DateTimeUtil.getYear(unprocessedEntry.atechDateTime), unprocessedEntry);
|
// DateTimeUtil.getYear(unprocessedEntry.atechDateTime), unprocessedEntry);
|
||||||
|
|
||||||
if (DateTimeUtil.getYear(unprocessedEntry.atechDateTime) > 2015)
|
if (DateTimeUtil.getYear(unprocessedEntry.atechDateTime) > 2015)
|
||||||
olderEntries++;
|
olderEntries++;
|
||||||
}
|
}
|
||||||
|
@ -131,14 +126,6 @@ public class PumpHistoryResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void clearOrPrepareList() {
|
|
||||||
if (this.validEntries == null)
|
|
||||||
this.validEntries = new ArrayList<>();
|
|
||||||
else
|
|
||||||
this.validEntries.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PumpHistoryResult [unprocessed=" + (unprocessedEntries != null ? "" + unprocessedEntries.size() : "0") + //
|
return "PumpHistoryResult [unprocessed=" + (unprocessedEntries != null ? "" + unprocessedEntries.size() : "0") + //
|
||||||
", valid=" + (validEntries != null ? "" + validEntries.size() : "0") + //
|
", valid=" + (validEntries != null ? "" + validEntries.size() : "0") + //
|
||||||
|
|
|
@ -49,6 +49,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpSta
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
@ -67,7 +68,6 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
|
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
|
||||||
|
|
||||||
public class MedtronicHistoryData {
|
public class MedtronicHistoryData {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
||||||
|
|
||||||
private List<PumpHistoryEntry> allHistory = null;
|
private List<PumpHistoryEntry> allHistory = null;
|
||||||
|
@ -77,6 +77,7 @@ public class MedtronicHistoryData {
|
||||||
private boolean isInit = false;
|
private boolean isInit = false;
|
||||||
|
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
private Gson gsonCore;
|
||||||
|
|
||||||
private DatabaseHelper databaseHelper = MainApp.getDbHelper();
|
private DatabaseHelper databaseHelper = MainApp.getDbHelper();
|
||||||
private ClockDTO pumpTime;
|
private ClockDTO pumpTime;
|
||||||
|
@ -94,10 +95,15 @@ public class MedtronicHistoryData {
|
||||||
public MedtronicHistoryData() {
|
public MedtronicHistoryData() {
|
||||||
this.allHistory = new ArrayList<>();
|
this.allHistory = new ArrayList<>();
|
||||||
this.gson = MedtronicUtil.gsonInstance;
|
this.gson = MedtronicUtil.gsonInstance;
|
||||||
|
this.gsonCore = MedtronicUtil.getGsonInstanceCore();
|
||||||
|
|
||||||
if (this.gson == null) {
|
if (this.gson == null) {
|
||||||
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.gsonCore == null) {
|
||||||
|
this.gsonCore = new GsonBuilder().create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -523,7 +529,7 @@ public class MedtronicHistoryData {
|
||||||
data.put("eventType", event);
|
data.put("eventType", event);
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
LOG.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +603,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
||||||
gson.toJson(entriesFromHistory));
|
gsonCore.toJson(entriesFromHistory));
|
||||||
|
|
||||||
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
|
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
|
||||||
|
|
||||||
|
@ -609,7 +615,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
|
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
|
||||||
gson.toJson(entriesFromHistory));
|
gsonCore.toJson(entriesFromHistory));
|
||||||
|
|
||||||
if (isCollectionEmpty(entriesFromHistory)) {
|
if (isCollectionEmpty(entriesFromHistory)) {
|
||||||
for (PumpHistoryEntry treatment : entryList) {
|
for (PumpHistoryEntry treatment : entryList) {
|
||||||
|
@ -862,6 +868,7 @@ public class MedtronicHistoryData {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>();
|
List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>();
|
||||||
|
List<PumpHistoryEntry> removeTreatmentsFromPH = new ArrayList<>();
|
||||||
|
|
||||||
for (DbObjectBase treatment : treatmentsFromHistory) {
|
for (DbObjectBase treatment : treatmentsFromHistory) {
|
||||||
|
|
||||||
|
@ -879,11 +886,17 @@ public class MedtronicHistoryData {
|
||||||
if (selectedBolus != null) {
|
if (selectedBolus != null) {
|
||||||
entryList.remove(selectedBolus);
|
entryList.remove(selectedBolus);
|
||||||
|
|
||||||
|
removeTreatmentsFromPH.add(selectedBolus);
|
||||||
removeTreatmentsFromHistory.add(treatment);
|
removeTreatmentsFromHistory.add(treatment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doubleBolusDebug)
|
||||||
|
LOG.debug("DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
|
||||||
|
gson.toJson(removeTreatmentsFromPH),
|
||||||
|
gsonCore.toJson(removeTreatmentsFromHistory));
|
||||||
|
|
||||||
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
|
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,36 +960,23 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(treatment.date, bolusDTO.getDeliveredAmount());
|
if (doubleBolusDebug)
|
||||||
|
LOG.debug("DoubleBolusDebug: addBolus(OldTreatment={}): Bolus={}", treatment, bolusDTO);
|
||||||
|
|
||||||
|
treatment.source = Source.PUMP;
|
||||||
|
treatment.pumpId = bolus.getPumpId();
|
||||||
|
treatment.insulin = bolusDTO.getDeliveredAmount();
|
||||||
|
|
||||||
|
TreatmentService.UpdateReturn updateReturn = TreatmentsPlugin.getPlugin().getService().createOrUpdateMedtronic(treatment, false);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament={}): Bolus={}, DetailedBolusInfo={}", treatment, bolusDTO, detailedBolusInfo);
|
LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): NewTreatment={}, UpdateReturn={}", treatment, updateReturn);
|
||||||
|
|
||||||
if (detailedBolusInfo == null) {
|
|
||||||
detailedBolusInfo = new DetailedBolusInfo();
|
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
|
||||||
LOG.debug("DoubleBolusDebug: detailedBolusInfoCouldNotBeRetrived !");
|
|
||||||
}
|
|
||||||
|
|
||||||
detailedBolusInfo.date = treatment.date;
|
|
||||||
detailedBolusInfo.source = Source.PUMP;
|
|
||||||
detailedBolusInfo.pumpId = bolus.getPumpId();
|
|
||||||
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
|
|
||||||
detailedBolusInfo.carbs = treatment.carbs;
|
|
||||||
|
|
||||||
addCarbsFromEstimate(detailedBolusInfo, bolus);
|
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): DetailedBolusInfo(New)={}", detailedBolusInfo);
|
|
||||||
|
|
||||||
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
|
||||||
|
|
||||||
bolus.setLinkedObject(detailedBolusInfo);
|
|
||||||
|
|
||||||
if (isLogEnabled())
|
if (isLogEnabled())
|
||||||
LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
|
LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", treatment.date,
|
||||||
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
|
treatment.pumpId, treatment.insulin, updateReturn.toString());
|
||||||
|
|
||||||
|
bolus.setLinkedObject(treatment);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,7 @@ public class MedtronicUtil extends RileyLinkUtil {
|
||||||
private static int doneBit = 1 << 7;
|
private static int doneBit = 1 << 7;
|
||||||
private static ClockDTO pumpTime;
|
private static ClockDTO pumpTime;
|
||||||
public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
|
public static Gson gsonInstanceCore = new GsonBuilder().create();
|
||||||
.setPrettyPrinting().create();
|
|
||||||
private static BatteryType batteryType = BatteryType.None;
|
private static BatteryType batteryType = BatteryType.None;
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,8 +69,9 @@ public class MedtronicUtil extends RileyLinkUtil {
|
||||||
return gsonInstance;
|
return gsonInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Gson getGsonInstancePretty() {
|
|
||||||
return gsonInstancePretty;
|
public static Gson getGsonInstanceCore() {
|
||||||
|
return gsonInstanceCore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.logging.L
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findDexcomPackageName(): String? {
|
fun findDexcomPackageName(): String? {
|
||||||
val packageManager = MainApp.instance().packageManager;
|
val packageManager = MainApp.instance().packageManager
|
||||||
for (packageInfo in packageManager.getInstalledPackages(0)) {
|
for (packageInfo in packageManager.getInstalledPackages(0)) {
|
||||||
if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName
|
if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName
|
||||||
}
|
}
|
||||||
|
@ -64,43 +65,53 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
|
||||||
val sensorType = intent.getStringExtra("sensorType") ?: ""
|
val sensorType = intent.getStringExtra("sensorType") ?: ""
|
||||||
val glucoseValues = intent.getBundleExtra("glucoseValues")
|
val glucoseValues = intent.getBundleExtra("glucoseValues")
|
||||||
for (i in 0 until glucoseValues.size()) {
|
for (i in 0 until glucoseValues.size()) {
|
||||||
val glucoseValue = glucoseValues.getBundle(i.toString())
|
glucoseValues.getBundle(i.toString())?.let { glucoseValue ->
|
||||||
val bgReading = BgReading()
|
val bgReading = BgReading()
|
||||||
bgReading.value = glucoseValue!!.getInt("glucoseValue").toDouble()
|
bgReading.value = glucoseValue.getInt("glucoseValue").toDouble()
|
||||||
bgReading.direction = glucoseValue.getString("trendArrow")
|
bgReading.direction = glucoseValue.getString("trendArrow")
|
||||||
bgReading.date = glucoseValue.getLong("timestamp") * 1000
|
bgReading.date = glucoseValue.getLong("timestamp") * 1000
|
||||||
bgReading.raw = 0.0
|
bgReading.raw = 0.0
|
||||||
if (MainApp.getDbHelper().createIfNotExists(bgReading, "Dexcom$sensorType")) {
|
if (MainApp.getDbHelper().createIfNotExists(bgReading, "Dexcom$sensorType")) {
|
||||||
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
NSUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType")
|
NSUpload.uploadBg(bgReading, "AndroidAPS-Dexcom$sensorType")
|
||||||
}
|
}
|
||||||
if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||||
NSUpload.sendToXdrip(bgReading)
|
NSUpload.sendToXdrip(bgReading)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val meters = intent.getBundleExtra("meters")
|
val meters = intent.getBundleExtra("meters")
|
||||||
for (i in 0 until meters.size()) {
|
for (i in 0 until meters.size()) {
|
||||||
val meter = meters.getBundle(i.toString())
|
val meter = meters.getBundle(i.toString())
|
||||||
val timestamp = meter!!.getLong("timestamp") * 1000
|
meter?.let {
|
||||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(timestamp) != null) continue
|
val timestamp = it.getLong("timestamp") * 1000
|
||||||
val jsonObject = JSONObject()
|
val now = DateUtil.now()
|
||||||
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
|
if (timestamp > now - T.months(1).msecs() && timestamp < now)
|
||||||
jsonObject.put("created_at", DateUtil.toISOString(timestamp))
|
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(timestamp) == null) {
|
||||||
jsonObject.put("eventType", CareportalEvent.BGCHECK)
|
val jsonObject = JSONObject()
|
||||||
jsonObject.put("glucoseType", "Finger")
|
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
|
||||||
jsonObject.put("glucose", meter.getInt("meterValue"))
|
jsonObject.put("created_at", DateUtil.toISOString(timestamp))
|
||||||
jsonObject.put("units", Constants.MGDL)
|
jsonObject.put("eventType", CareportalEvent.BGCHECK)
|
||||||
NSUpload.uploadCareportalEntryToNS(jsonObject)
|
jsonObject.put("glucoseType", "Finger")
|
||||||
|
jsonObject.put("glucose", meter.getInt("meterValue"))
|
||||||
|
jsonObject.put("units", Constants.MGDL)
|
||||||
|
NSUpload.uploadCareportalEntryToNS(jsonObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false) && intent.hasExtra("sensorInsertionTime")) {
|
if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false) && intent.hasExtra("sensorInsertionTime")) {
|
||||||
val sensorInsertionTime = intent.extras!!.getLong("sensorInsertionTime") * 1000
|
intent.extras?.let {
|
||||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) {
|
val sensorInsertionTime = it.getLong("sensorInsertionTime") * 1000
|
||||||
val jsonObject = JSONObject()
|
val now = DateUtil.now()
|
||||||
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
|
if (sensorInsertionTime > now - T.months(1).msecs() && sensorInsertionTime < now)
|
||||||
jsonObject.put("created_at", DateUtil.toISOString(sensorInsertionTime))
|
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) {
|
||||||
jsonObject.put("eventType", CareportalEvent.SENSORCHANGE)
|
val jsonObject = JSONObject()
|
||||||
NSUpload.uploadCareportalEntryToNS(jsonObject)
|
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
|
||||||
|
jsonObject.put("created_at", DateUtil.toISOString(sensorInsertionTime))
|
||||||
|
jsonObject.put("eventType", CareportalEvent.SENSORCHANGE)
|
||||||
|
NSUpload.uploadCareportalEntryToNS(jsonObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
try {
|
try {
|
||||||
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` ADD COLUMN boluscalc STRING;");
|
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` ADD COLUMN boluscalc STRING;");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
|
@ -147,7 +147,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
try {
|
try {
|
||||||
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` DROP COLUMN boluscalc STRING;");
|
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` DROP COLUMN boluscalc STRING;");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,6 +736,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
boolean newRecord;
|
boolean newRecord;
|
||||||
boolean success;
|
boolean success;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UpdateReturn [" +
|
||||||
|
"newRecord=" + newRecord +
|
||||||
|
", success=" + success +
|
||||||
|
']';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
synchronized (treatments) {
|
synchronized (treatments) {
|
||||||
if (MedtronicHistoryData.doubleBolusDebug)
|
if (MedtronicHistoryData.doubleBolusDebug)
|
||||||
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments));
|
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstanceCore().toJson(treatments));
|
||||||
|
|
||||||
for (Treatment t : treatments) {
|
for (Treatment t : treatments) {
|
||||||
if (t.date <= time && t.date >= fromTimestamp)
|
if (t.date <= time && t.date >= fromTimestamp)
|
||||||
|
@ -357,7 +357,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MedtronicHistoryData.doubleBolusDebug)
|
if (MedtronicHistoryData.doubleBolusDebug)
|
||||||
log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback));
|
log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstanceCore().toJson(in5minback));
|
||||||
|
|
||||||
return in5minback;
|
return in5minback;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ChargingStateReceiver extends BroadcastReceiver {
|
||||||
lastEvent = event;
|
lastEvent = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventChargingState grabChargingState(Context context) {
|
public static EventChargingState grabChargingState(Context context) {
|
||||||
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||||
|
|
||||||
if (bm == null)
|
if (bm == null)
|
||||||
|
|
|
@ -26,11 +26,6 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
public static final NetworkChangeReceiver instance = new NetworkChangeReceiver();
|
public static final NetworkChangeReceiver instance = new NetworkChangeReceiver();
|
||||||
|
|
||||||
// TODO: Split NSClient into network state component that can be used by several plugins and logic for plugin
|
|
||||||
public static void fetch() {
|
|
||||||
new NetworkChangeReceiver().grabNetworkStatus(MainApp.instance().getApplicationContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, final Intent intent) {
|
public void onReceive(final Context context, final Intent intent) {
|
||||||
EventNetworkChange event = grabNetworkStatus(context);
|
EventNetworkChange event = grabNetworkStatus(context);
|
||||||
|
@ -39,7 +34,7 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public EventNetworkChange grabNetworkStatus(final Context context) {
|
public static EventNetworkChange grabNetworkStatus(final Context context) {
|
||||||
EventNetworkChange event = new EventNetworkChange();
|
EventNetworkChange event = new EventNetworkChange();
|
||||||
|
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package info.nightscout.androidaps.utils;
|
package info.nightscout.androidaps.utils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 20.06.2016.
|
* Created by mike on 20.06.2016.
|
||||||
*/
|
*/
|
||||||
public class Round {
|
public class Round {
|
||||||
public static Double roundTo(double x, Double step) {
|
public static Double roundTo(double x, Double step) {
|
||||||
if (x != 0d) {
|
if (x == 0d) {
|
||||||
return Math.round(x / step) * step;
|
return 0d;
|
||||||
}
|
}
|
||||||
return 0d;
|
|
||||||
|
//Double oldCalc = Math.round(x / step) * step;
|
||||||
|
Double newCalc = BigDecimal.valueOf(Math.round(x / step)).multiply(BigDecimal.valueOf(step)).doubleValue();
|
||||||
|
|
||||||
|
// just for the tests, forcing failures
|
||||||
|
//newCalc = oldCalc;
|
||||||
|
|
||||||
|
return newCalc;
|
||||||
}
|
}
|
||||||
public static Double floorTo(Double x, Double step) {
|
public static Double floorTo(Double x, Double step) {
|
||||||
if (x != 0d) {
|
if (x != 0d) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class QuickWizardTest {
|
||||||
try {
|
try {
|
||||||
array = new JSONArray("[" + data1 + "," + data2 + "]");
|
array = new JSONArray("[" + data1 + "," + data2 + "]");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class TriggerBgTest {
|
||||||
try {
|
try {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":" + (now - 1) + ",\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":" + (now - 1) + ",\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class TriggerDeltaTest {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))));
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,7 @@ public class NsClientReceiverDelegateTest {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockApplicationContext();
|
AAPSMocker.mockApplicationContext();
|
||||||
|
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
sut = new NsClientReceiverDelegate();
|
||||||
|
|
||||||
sut = new NsClientReceiverDelegate(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class GlucoseStatusTest {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":226,\"mills\":1514765100000,\"direction\":\"Flat\"}"))));
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ public class GlucoseStatusTest {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))); // +2
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766800000,\"direction\":\"Flat\"}")))); // +2
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":216,\"mills\":1514766600000,\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ public class GlucoseStatusTest {
|
||||||
try {
|
try {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":228,\"mills\":1514764800000,\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ public class GlucoseStatusTest {
|
||||||
try {
|
try {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":214,\"mills\":1514766900000,\"direction\":\"Flat\"}"))));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ public class GlucoseStatusTest {
|
||||||
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading + (i*2)) + ",\"mills\":" + (end_time - (1000 * 60 * i)) + ",\"direction\":\"Flat\"}"))));
|
list.add(new BgReading(new NSSgv(new JSONObject("{\"mgdl\":" + (latest_reading + (i*2)) + ",\"mills\":" + (end_time - (1000 * 60 * i)) + ",\"direction\":\"Flat\"}"))));
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,16 @@ public class RoundTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void roundToTest() throws Exception {
|
public void roundToTest() throws Exception {
|
||||||
assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d );
|
assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000000000000000001d );
|
||||||
assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d );
|
assertEquals( -3.26d, Round.roundTo(-3.2553715764602713d, 0.01d), 0.00000000000000000001d );
|
||||||
assertEquals( 0d, Round.roundTo(0d, 1d), 0.00000001d );
|
assertEquals( 0.816d, Round.roundTo(0.8156666666666667d, 0.001d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 0.235d, Round.roundTo(0.235d, 0.001d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 0.3d, Round.roundTo(0.3d, 0.1d), 0.00000000000000001d );
|
||||||
|
assertEquals( 0.0017d, Round.roundTo(0.0016960652144170627d, 0.0001d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 0.0078d, Round.roundTo(0.007804436682291013d, 0.0001d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 0.6d, Round.roundTo(0.6d, 0.05d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000000000000000001d );
|
||||||
|
assertEquals( 0d, Round.roundTo(0d, 1d), 0.00000000000000000001d );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -3,6 +3,7 @@ apply plugin: 'com.android.application'
|
||||||
ext {
|
ext {
|
||||||
wearableVersion = "2.4.0"
|
wearableVersion = "2.4.0"
|
||||||
playServicesWearable = "17.0.0"
|
playServicesWearable = "17.0.0"
|
||||||
|
powermockVersion = "1.7.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateGitBuild = { ->
|
def generateGitBuild = { ->
|
||||||
|
@ -105,4 +106,18 @@ dependencies {
|
||||||
implementation 'androidx.wear:wear:1.0.0'
|
implementation 'androidx.wear:wear:1.0.0'
|
||||||
implementation('me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0')
|
implementation('me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0')
|
||||||
implementation('com.github.lecho:hellocharts-library:1.5.8@aar')
|
implementation('com.github.lecho:hellocharts-library:1.5.8@aar')
|
||||||
|
|
||||||
|
testImplementation "junit:junit:4.12"
|
||||||
|
testImplementation "org.json:json:20140107"
|
||||||
|
testImplementation "org.mockito:mockito-core:2.8.47"
|
||||||
|
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
|
||||||
|
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||||
|
testImplementation "joda-time:joda-time:2.9.9"
|
||||||
|
testImplementation("com.google.truth:truth:0.39") {
|
||||||
|
exclude group: "com.google.guava", module: "guava"
|
||||||
|
}
|
||||||
|
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
||||||
|
testImplementation "org.hamcrest:hamcrest-all:1.3"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
package info.nightscout.androidaps.interaction.utils;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by dlvoy on 21.11.2019.
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
public class SafeParseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToDoubleTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(0.1234, is(SafeParse.stringToDouble("0.1234")));
|
||||||
|
assertThat(0.1234, is(SafeParse.stringToDouble("0,1234")));
|
||||||
|
assertThat(0.5436564812, is(SafeParse.stringToDouble(".5436564812")));
|
||||||
|
assertThat(0.5436564812, is(SafeParse.stringToDouble(",5436564812")));
|
||||||
|
assertThat(1000500100900.0, is(SafeParse.stringToDouble("1000500100900")));
|
||||||
|
assertThat(42.0, is(SafeParse.stringToDouble("42")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("12 U/h")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("ala ma kota")));
|
||||||
|
|
||||||
|
// separator errors
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("0.1234.5678")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("0,1234,5678")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble(" ")));
|
||||||
|
assertThat(0.0, is(SafeParse.stringToDouble("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToIntTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(1052934, is(SafeParse.stringToInt("1052934")));
|
||||||
|
assertThat(-42, is(SafeParse.stringToInt("-42")));
|
||||||
|
assertThat(2147483647, is(SafeParse.stringToInt("2147483647")));
|
||||||
|
assertThat(-2147483648, is(SafeParse.stringToInt("-2147483648")));
|
||||||
|
|
||||||
|
// outside Integer range
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("2147483648")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("-2147483649")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("12 U/h")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("0.1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("0,1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(".5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(",5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("42.1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("42,1234")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("3212.5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("3212,5436564812")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("1000500100900")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("ala ma kota")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt(" ")));
|
||||||
|
assertThat(0, is(SafeParse.stringToInt("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stringToLongTest() {
|
||||||
|
// correct values
|
||||||
|
assertThat(1052934L, is(SafeParse.stringToLong("1052934")));
|
||||||
|
assertThat(-42L, is(SafeParse.stringToLong("-42")));
|
||||||
|
assertThat(2147483647L, is(SafeParse.stringToLong("2147483647")));
|
||||||
|
assertThat(-2147483648L, is(SafeParse.stringToLong("-2147483648")));
|
||||||
|
assertThat(1000500100900L, is(SafeParse.stringToLong("1000500100900")));
|
||||||
|
|
||||||
|
// outside Integer range
|
||||||
|
assertThat(2147483648L, is(SafeParse.stringToLong("2147483648")));
|
||||||
|
assertThat(-2147483649L, is(SafeParse.stringToLong("-2147483649")));
|
||||||
|
|
||||||
|
// units or other extra values are not permitted
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("12 U/h")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("0.1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("0,1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(".5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(",5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("42.1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("42,1234")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("3212.5436564812")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("3212,5436564812")));
|
||||||
|
|
||||||
|
// strings are not parsable
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("ala ma kota")));
|
||||||
|
|
||||||
|
// various emptiness
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong(" ")));
|
||||||
|
assertThat(0L, is(SafeParse.stringToLong("\n\r")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToDoubleNullTest() {
|
||||||
|
SafeParse.stringToDouble(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToIntNullTest() {
|
||||||
|
SafeParse.stringToInt(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void stringToLongNullTest() {
|
||||||
|
SafeParse.stringToLong(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepareMock() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue