Clean up ComoPlugin a bit.

This commit is contained in:
Johannes Mockenhaupt 2017-07-16 03:40:05 +02:00
parent ccd81c67fd
commit b954ddaa84
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -101,6 +101,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
log.debug("Querying pump for initial state");
runCommand(new NoOpCommand()); runCommand(new NoOpCommand());
} }
}).start(); }).start();
@ -305,36 +306,41 @@ public class ComboPlugin implements PluginBase, PumpInterface {
} }
} }
private CommandResult runCommand(Command command) { // TODO if there was some clue as to what refreshDataFromPump would do with the data ...
synchronized (this) { // that method calls NSUpload.uploadDeviceStatus(); in VirtualPump ...
// TODO use this to dispatch methods to a service thread, like DanaRs executionService public PumpState fetchPumpState() {
// will be required when doing multiple commands in sequence. CommandResult commandResult = runCommand(new NoOpCommand());
// Alternatively provide 'composite commands' to return everything needed in one go? if (commandResult.success) {
CommandResult commandResult = null; pumpState = commandResult.state;
try { return commandResult.state;
statusSummary = "Busy running " + command; } else {
pumpState = null; return new PumpState().errorMsg("Failure reading state from pump: " + commandResult.message);
MainApp.bus().post(new EventComboPumpUpdateGUI()); }
commandResult = ruffyScripter.runCommand(command); }
if (commandResult.success && commandResult.state != null) {
pumpState = commandResult.state;
}
return commandResult;
} finally {
lastCmdTime = new Date();
statusSummary = "Idle";
PumpState ps = pumpState;
if (ps != null) {
if (ps.errorMsg != null) {
statusSummary = "Error: " + ps.errorMsg;
} else if (ps.isErrorOrWarning) {
statusSummary = "Error: pump is in error mode, please check pump display";
}
}
ruffyScripter.disconnect(); private CommandResult runCommand(Command command) {
MainApp.bus().post(new EventComboPumpUpdateGUI()); CommandResult commandResult;
try {
statusSummary = "Busy running " + command;
pumpState = null;
MainApp.bus().post(new EventComboPumpUpdateGUI());
commandResult = ruffyScripter.runCommand(command);
if (commandResult.success && commandResult.state != null) {
pumpState = commandResult.state;
} }
return commandResult;
} finally {
lastCmdTime = new Date();
statusSummary = "Idle";
PumpState ps = pumpState;
if (ps != null) {
if (ps.errorMsg != null) {
statusSummary = "Error: " + ps.errorMsg;
} else if (ps.isErrorOrWarning) {
statusSummary = "Error: pump is in error mode, please check pump display";
}
}
MainApp.bus().post(new EventComboPumpUpdateGUI());
} }
} }
@ -354,17 +360,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
if (unroundedPercentage != roundedPercentage) { if (unroundedPercentage != roundedPercentage) {
log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%"); log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%");
} }
PumpState ps = pumpState;
int activeTbrPercentage = ps != null ? ps.tbrPercent : 100;
if (activeTbrPercentage != -1 && Math.abs(activeTbrPercentage - roundedPercentage) <= 20) {
log.debug("Not bothering the pump for a small TBR change from " + activeTbrPercentage + "% -> " + roundedPercentage + "%");
PumpEnactResult pumpEnactResult = new PumpEnactResult();
pumpEnactResult.success = true;
pumpEnactResult.enacted = false;
pumpEnactResult.percent = activeTbrPercentage;
pumpEnactResult.comment = "TBR change too small, skipping change from " + activeTbrPercentage + "% -> " + roundedPercentage + "%";
return pumpEnactResult;
}
int stepSize = pumpDescription.tempDurationStep; int stepSize = pumpDescription.tempDurationStep;
if (durationInMinutes > stepSize) { if (durationInMinutes > stepSize) {
log.debug("Reducing requested duration of " + durationInMinutes + "m to minimal duration supported by the pump: " + stepSize + "m"); log.debug("Reducing requested duration of " + durationInMinutes + "m to minimal duration supported by the pump: " + stepSize + "m");
@ -411,7 +406,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
return OPERATION_NOT_SUPPORTED; return OPERATION_NOT_SUPPORTED;
} }
// TODO untested, probably not working
@Override @Override
public PumpEnactResult cancelTempBasal() { public PumpEnactResult cancelTempBasal() {
log.debug("cancelTempBasal called"); log.debug("cancelTempBasal called");