From 5d74f71d0aeaf6b88f3719d3030509ca7250fef3 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 30 Dec 2021 19:29:18 +0100 Subject: [PATCH] OBJECTIVES: Better detect existing BGs --- .../nsclient/services/NSClientService.kt | 22 +++++++++++-------- .../plugins/source/NSClientSourcePlugin.kt | 2 -- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt index 60026fd700..040fe82453 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt @@ -16,8 +16,6 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.DataSyncSelector -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.food.FoodPlugin.FoodWorker import info.nightscout.androidaps.plugins.general.nsclient.* @@ -48,6 +46,8 @@ import info.nightscout.androidaps.utils.XDripBroadcast import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import io.reactivex.disposables.CompositeDisposable import io.socket.client.IO @@ -540,13 +540,17 @@ class NSClientService : DaggerService() { } if (data.has("sgvs")) { val sgvs = data.getJSONArray("sgvs") - if (sgvs.length() > 0) rxBus.send(EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs")) - dataWorker.enqueue( - OneTimeWorkRequest.Builder(NSClientSourceWorker::class.java) - .setInputData(dataWorker.storeInputData(sgvs, null)) - .build() - ) - xDripBroadcast.sendSgvs(sgvs) + if (sgvs.length() > 0) { + rxBus.send(EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs")) + // Objective0 + sp.putBoolean(R.string.key_ObjectivesbgIsAvailableInNS, true) + dataWorker.enqueue( + OneTimeWorkRequest.Builder(NSClientSourceWorker::class.java) + .setInputData(dataWorker.storeInputData(sgvs, null)) + .build() + ) + xDripBroadcast.sendSgvs(sgvs) + } } rxBus.send(EventNSClientNewLog("LAST", dateUtil.dateAndTimeString(latestDateInReceivedData))) } catch (e: JSONException) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt index 307aaff4b6..a640df98fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt @@ -162,8 +162,6 @@ class NSClientSourcePlugin @Inject constructor( aapsLogger.error("Unhandled exception", e) ret = Result.failure(workDataOf("Error" to e.toString())) } - // Objectives 0 - sp.putBoolean(R.string.key_ObjectivesbgIsAvailableInNS, true) return ret } }