Fix DeviceStatus upload

This commit is contained in:
Milos Kozak 2020-01-03 21:02:36 +01:00
parent 2470cc7b17
commit 5602819321
9 changed files with 21 additions and 19 deletions

View file

@ -98,6 +98,8 @@ abstract class PluginBase(pluginDesc: PluginDescription) {
open val preferencesId: Int
get() = pluginDescription.preferencesId
fun isEnabled() = isEnabled(pluginDescription.mainType)
fun isEnabled(type: PluginType): Boolean {
if (pluginDescription.alwaysEnabled && type == pluginDescription.mainType) return true
if (pluginDescription.mainType == PluginType.CONSTRAINTS && type == PluginType.CONSTRAINTS) return true

View file

@ -367,7 +367,7 @@ public class LoopPlugin extends PluginBase {
lastRun.tbrSetByPump = null;
lastRun.smbSetByPump = null;
NSUpload.uploadDeviceStatus();
NSUpload.uploadDeviceStatus(this);
if (isSuspended()) {
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended));
@ -480,7 +480,7 @@ public class LoopPlugin extends PluginBase {
public void acceptChangeRequest() {
Profile profile = profileFunction.getProfile();
final LoopPlugin lp = this;
applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
@ -488,7 +488,7 @@ public class LoopPlugin extends PluginBase {
lastRun.tbrSetByPump = result;
lastRun.lastEnact = new Date();
lastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
NSUpload.uploadDeviceStatus(lp);
sp.incInt(R.string.key_ObjectivesmanualEnacts);
}
rxBus.send(new EventAcceptOpenLoopChange());

View file

@ -50,16 +50,9 @@ import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 26.05.2017.
*/
@Singleton
public class NSUpload {
private static Logger log = LoggerFactory.getLogger(L.NSCLIENT);
private static LoopPlugin loopPlugin; // Ugly but temporary
@Inject
public NSUpload(LoopPlugin loopPlugin) {
this.loopPlugin = loopPlugin;
}
public static void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) {
try {
JSONObject data = new JSONObject();
@ -167,7 +160,7 @@ public class NSUpload {
}
}
public static void uploadDeviceStatus() {
public static void uploadDeviceStatus(LoopPlugin loopPlugin) {
Profile profile = ProfileFunctions.getInstance().getProfile();
String profileName = ProfileFunctions.getInstance().getProfileName();
@ -178,7 +171,6 @@ public class NSUpload {
DeviceStatus deviceStatus = new DeviceStatus();
try {
if (loopPlugin == null) return; // TODO ugly - not initialized yet
LoopPlugin.LastRun lastRun = loopPlugin.lastRun;
if (lastRun != null && lastRun.lastAPSRun.getTime() > System.currentTimeMillis() - 300 * 1000L) {
// do not send if result is older than 1 min

View file

@ -229,7 +229,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);

View file

@ -219,7 +219,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);

View file

@ -233,7 +233,7 @@ public class DanaRSService extends Service {
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);

View file

@ -262,7 +262,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
NSUpload.uploadDeviceStatus();
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);

View file

@ -166,7 +166,7 @@ class VirtualPumpPlugin @Inject constructor(
override fun finishHandshaking() {}
override fun connect(reason: String) {
if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
//if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
lastDataTime = System.currentTimeMillis()
}

View file

@ -8,6 +8,8 @@ import android.content.Intent
import android.os.PowerManager
import android.os.SystemClock
import dagger.android.DaggerBroadcastReceiver
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.db.DatabaseHelper
import info.nightscout.androidaps.events.EventProfileNeedsUpdate
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L
@ -87,14 +89,20 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
}
}
// Usually devicestatus is uploaded through LoopPlugin after every loop cycle.
// if there is no BG available, we have to upload anyway to have correct
// IOB displayed in NS
private fun checkAPS() {
val usedAPS = configBuilderPlugin.activeAPS
var shouldUploadStatus = false
if (usedAPS == null) shouldUploadStatus = true
if (Config.NSCLIENT) return
if (Config.PUMPCONTROL) shouldUploadStatus = true
if (usedAPS == null || !loopPlugin.isEnabled() || DatabaseHelper.actualBg() == null)
shouldUploadStatus = true
else if (DateUtil.isOlderThan(usedAPS.lastAPSRun, 5)) shouldUploadStatus = true
if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) {
lastIobUpload = DateUtil.now()
NSUpload.uploadDeviceStatus()
NSUpload.uploadDeviceStatus(loopPlugin)
}
}