eliminate IobCobCalculatorPlugin::getPlugin
This commit is contained in:
parent
e63169a94b
commit
156738a5cb
5 changed files with 23 additions and 27 deletions
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
|
|||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
@ -25,9 +26,10 @@ class IobCobStaticCalculatorPlugin @Inject constructor(
|
|||
treatmentsPlugin: TreatmentsPlugin,
|
||||
sensitivityOref1Plugin: SensitivityOref1Plugin,
|
||||
sensitivityAAPSPlugin: SensitivityAAPSPlugin,
|
||||
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin
|
||||
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin,
|
||||
fabricPrivacy: FabricPrivacy
|
||||
) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction,
|
||||
activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin) {
|
||||
activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy) {
|
||||
|
||||
override fun onStart() { // do not attach to rxbus
|
||||
}
|
||||
|
|
|
@ -391,7 +391,7 @@ public class LoopPlugin extends PluginBase {
|
|||
lastRun.lastSMBEnact = 0;
|
||||
lastRun.lastSMBRequest = 0;
|
||||
|
||||
NSUpload.uploadDeviceStatus(this);
|
||||
NSUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump());
|
||||
|
||||
if (isSuspended()) {
|
||||
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended));
|
||||
|
@ -516,7 +516,7 @@ public class LoopPlugin extends PluginBase {
|
|||
lastRun.lastTBRRequest = lastRun.lastAPSRun.getTime();
|
||||
lastRun.lastTBREnact = DateUtil.now();
|
||||
lastRun.lastOpenModeAccept = DateUtil.now();
|
||||
NSUpload.uploadDeviceStatus(lp);
|
||||
NSUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump());
|
||||
sp.incInt(R.string.key_ObjectivesmanualEnacts);
|
||||
}
|
||||
rxBus.send(new EventAcceptOpenLoopChange());
|
||||
|
|
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.db.ExtendedBolus;
|
|||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||
|
@ -160,9 +161,9 @@ public class NSUpload {
|
|||
}
|
||||
}
|
||||
|
||||
public static void uploadDeviceStatus(LoopPlugin loopPlugin) {
|
||||
Profile profile = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfile();
|
||||
String profileName = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfileName();
|
||||
public static void uploadDeviceStatus(LoopPlugin loopPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface) {
|
||||
Profile profile = profileFunction.getProfile();
|
||||
String profileName = profileFunction.getProfileName();
|
||||
|
||||
if (profile == null || profileName == null) {
|
||||
log.error("Profile is null. Skipping upload");
|
||||
|
@ -204,14 +205,14 @@ public class NSUpload {
|
|||
} else {
|
||||
if (L.isEnabled(L.NSCLIENT))
|
||||
log.debug("OpenAPS data too old to upload, sending iob only");
|
||||
IobTotal[] iob = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||
IobTotal[] iob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile);
|
||||
if (iob.length > 0) {
|
||||
deviceStatus.iob = iob[0].json();
|
||||
deviceStatus.iob.put("time", DateUtil.toISOString(DateUtil.now()));
|
||||
}
|
||||
}
|
||||
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
||||
JSONObject pumpstatus = PluginStore.Companion.getInstance().getActivePump().getJSONStatus(profile, profileName);
|
||||
JSONObject pumpstatus = pumpInterface.getJSONStatus(profile, profileName);
|
||||
if (pumpstatus != null) {
|
||||
deviceStatus.pump = pumpstatus;
|
||||
}
|
||||
|
|
|
@ -66,18 +66,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
private final SensitivityOref1Plugin sensitivityOref1Plugin;
|
||||
private final SensitivityAAPSPlugin sensitivityAAPSPlugin;
|
||||
private final SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin;
|
||||
private final FabricPrivacy fabricPrivacy;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static IobCobCalculatorPlugin plugin = null;
|
||||
|
||||
@Deprecated
|
||||
public static IobCobCalculatorPlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
throw new IllegalStateException("Accessing IobCobCalculatorPlugin before first instantiation");
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private LongSparseArray<BasalData> basalDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
|
@ -102,7 +94,8 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
TreatmentsPlugin treatmentsPlugin,
|
||||
SensitivityOref1Plugin sensitivityOref1Plugin,
|
||||
SensitivityAAPSPlugin sensitivityAAPSPlugin,
|
||||
SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin
|
||||
SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin,
|
||||
FabricPrivacy fabricPrivacy
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
|
@ -112,7 +105,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
.alwaysEnabled(true),
|
||||
aapsLogger, resourceHelper, injector
|
||||
);
|
||||
this.plugin = this;
|
||||
this.injector = injector;
|
||||
this.sp = sp;
|
||||
this.rxBus = rxBus;
|
||||
|
@ -123,6 +115,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
this.sensitivityOref1Plugin = sensitivityOref1Plugin;
|
||||
this.sensitivityAAPSPlugin = sensitivityAAPSPlugin;
|
||||
this.sensitivityWeightedAveragePlugin = sensitivityWeightedAveragePlugin;
|
||||
this.fabricPrivacy = fabricPrivacy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,7 +133,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventConfigBuilderChange", System.currentTimeMillis(), false, true, event);
|
||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
}, fabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBasalProfile
|
||||
disposable.add(rxBus
|
||||
|
@ -158,7 +151,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
basalDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
}, fabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBG
|
||||
disposable.add(rxBus
|
||||
|
@ -167,7 +160,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
.subscribe(event -> {
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
}, fabricPrivacy::logException)
|
||||
);
|
||||
// EventPreferenceChange
|
||||
disposable.add(rxBus
|
||||
|
@ -192,19 +185,19 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
||||
}
|
||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
}, fabricPrivacy::logException)
|
||||
);
|
||||
// EventAppInitialized
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAppInitialized.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), fabricPrivacy::logException)
|
||||
);
|
||||
// EventNewHistoryData
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventNewHistoryData.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(this::newHistoryData, exception -> FabricPrivacy.getInstance().logException(exception))
|
||||
.subscribe(this::newHistoryData, fabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
|||
else if (DateUtil.isOlderThan(usedAPS.lastAPSRun, 5)) shouldUploadStatus = true
|
||||
if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) {
|
||||
lastIobUpload = DateUtil.now()
|
||||
NSUpload.uploadDeviceStatus(loopPlugin)
|
||||
NSUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue