From aab171932c6250c01cec4bc7ee7371ce5204096c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 22 Jun 2018 18:57:02 +0200 Subject: [PATCH] Have Bgsource.processNewData return added BGs. --- .../androidaps/Services/DataService.java | 90 +++++++------------ .../interfaces/BgSourceInterface.java | 6 +- .../plugins/Source/SourceDexcomG5Plugin.java | 27 ++++-- .../plugins/Source/SourceGlimpPlugin.java | 10 ++- .../plugins/Source/SourceMM640gPlugin.java | 18 ++-- .../plugins/Source/SourceNSClientPlugin.java | 45 +++++++++- .../plugins/Source/SourcePoctechPlugin.java | 25 ++++-- .../plugins/Source/SourceXdripPlugin.java | 9 +- 8 files changed, 142 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 2b6d1c1604..7cdd287316 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -71,6 +71,8 @@ public class DataService extends IntentService { protected void onHandleIntent(final Intent intent) { if (intent == null) return; + if (Config.logIncommingData) + log.debug("Got intent: " + intent.getAction()); if (Config.logFunctionCalls) log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras())); if (ConfigBuilderPlugin.getActiveBgSource() == null) { @@ -203,25 +205,21 @@ public class DataService extends IntentService { } private void processNewBgIntent(BgSourceInterface bgSource, Intent intent) { - if (Config.logIncommingData) - log.debug("Got intent: " + intent.getAction()); Bundle bundle = intent.getExtras(); if (bundle == null) return; bgSource.processNewData(bundle); } private void handleNewDataFromNSClient(Intent intent) { - Bundle bundles = intent.getExtras(); - if (bundles == null) return; - - + Bundle bundle = intent.getExtras(); + if (bundle == null) return; if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) { - if (bundles.containsKey("nsclientversioncode")) { - ConfigBuilderPlugin.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203 - ConfigBuilderPlugin.nightscoutVersionName = bundles.getString("nightscoutversionname"); - ConfigBuilderPlugin.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117 - ConfigBuilderPlugin.nsClientVersionName = bundles.getString("nsclientversionname"); + if (bundle.containsKey("nsclientversioncode")) { + ConfigBuilderPlugin.nightscoutVersionCode = bundle.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203 + ConfigBuilderPlugin.nightscoutVersionName = bundle.getString("nightscoutversionname"); + ConfigBuilderPlugin.nsClientVersionCode = bundle.getInt("nsclientversioncode"); // for ver 1.17 contains 117 + ConfigBuilderPlugin.nsClientVersionName = bundle.getString("nsclientversionname"); log.debug("Got versions: NSClient: " + ConfigBuilderPlugin.nsClientVersionName + " Nightscout: " + ConfigBuilderPlugin.nightscoutVersionName); try { if (ConfigBuilderPlugin.nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) { @@ -243,9 +241,9 @@ public class DataService extends IntentService { Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); } - if (bundles.containsKey("status")) { + if (bundle.containsKey("status")) { try { - JSONObject statusJson = new JSONObject(bundles.getString("status")); + JSONObject statusJson = new JSONObject(bundle.getString("status")); NSSettingsStatus.getInstance().setData(statusJson); if (Config.logIncommingData) log.debug("Received status: " + statusJson.toString()); @@ -262,8 +260,8 @@ public class DataService extends IntentService { } if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) { try { - if (bundles.containsKey("devicestatus")) { - JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus")); + if (bundle.containsKey("devicestatus")) { + JSONObject devicestatusJson = new JSONObject(bundle.getString("devicestatus")); NSDeviceStatus.getInstance().setData(devicestatusJson); if (devicestatusJson.has("pump")) { // Objectives 0 @@ -271,8 +269,8 @@ public class DataService extends IntentService { ObjectivesPlugin.saveProgress(); } } - if (bundles.containsKey("devicestatuses")) { - String devicestatusesstring = bundles.getString("devicestatuses"); + if (bundle.containsKey("devicestatuses")) { + String devicestatusesstring = bundle.getString("devicestatuses"); JSONArray jsonArray = new JSONArray(devicestatusesstring); for (int i = 0; i < jsonArray.length(); i++) { JSONObject devicestatusJson = jsonArray.getJSONObject(i); @@ -291,8 +289,8 @@ public class DataService extends IntentService { // Handle profile if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) { try { - String activeProfile = bundles.getString("activeprofile"); - String profile = bundles.getString("profile"); + String activeProfile = bundle.getString("activeprofile"); + String profile = bundle.getString("profile"); ProfileStore profileStore = new ProfileStore(new JSONObject(profile)); NSProfilePlugin.getPlugin().storeNewProfile(profileStore); MainApp.bus().post(new EventNSProfileUpdateGUI()); @@ -305,12 +303,12 @@ public class DataService extends IntentService { if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) { try { - if (bundles.containsKey("treatment")) { - JSONObject json = new JSONObject(bundles.getString("treatment")); + if (bundle.containsKey("treatment")) { + JSONObject json = new JSONObject(bundle.getString("treatment")); handleTreatmentFromNS(json, intent); } - if (bundles.containsKey("treatments")) { - String trstring = bundles.getString("treatments"); + if (bundle.containsKey("treatments")) { + String trstring = bundle.getString("treatments"); JSONArray jsonArray = new JSONArray(trstring); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); @@ -324,14 +322,14 @@ public class DataService extends IntentService { if (intent.getAction().equals(Intents.ACTION_REMOVED_TREATMENT)) { try { - if (bundles.containsKey("treatment")) { - String trstring = bundles.getString("treatment"); + if (bundle.containsKey("treatment")) { + String trstring = bundle.getString("treatment"); JSONObject json = new JSONObject(trstring); handleTreatmentFromNS(json); } - if (bundles.containsKey("treatments")) { - String trstring = bundles.getString("treatments"); + if (bundle.containsKey("treatments")) { + String trstring = bundle.getString("treatments"); JSONArray jsonArray = new JSONArray(trstring); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); @@ -344,36 +342,19 @@ public class DataService extends IntentService { } if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) { - try { - if (bundles.containsKey("sgv")) { - String sgvstring = bundles.getString("sgv"); - JSONObject sgvJson = new JSONObject(sgvstring); - storeSgv(sgvJson); - } - - if (bundles.containsKey("sgvs")) { - String sgvstring = bundles.getString("sgvs"); - JSONArray jsonArray = new JSONArray(sgvstring); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject sgvJson = jsonArray.getJSONObject(i); - storeSgv(sgvJson); - } - } - } catch (Exception e) { - log.error("Unhandled exception", e); - } + SourceNSClientPlugin.getPlugin().processNewData(bundle); } if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) { try { - if (bundles.containsKey("mbg")) { - String mbgstring = bundles.getString("mbg"); + if (bundle.containsKey("mbg")) { + String mbgstring = bundle.getString("mbg"); JSONObject mbgJson = new JSONObject(mbgstring); storeMbg(mbgJson); } - if (bundles.containsKey("mbgs")) { - String sgvstring = bundles.getString("mbgs"); + if (bundle.containsKey("mbgs")) { + String sgvstring = bundle.getString("mbgs"); JSONArray jsonArray = new JSONArray(sgvstring); for (int i = 0; i < jsonArray.length(); i++) { JSONObject mbgJson = jsonArray.getJSONObject(i); @@ -388,12 +369,12 @@ public class DataService extends IntentService { if (intent.getAction().equals(Intents.ACTION_NEW_FOOD) || intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) { int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE; - EventNsFood evt = new EventNsFood(mode, bundles); + EventNsFood evt = new EventNsFood(mode, bundle); MainApp.bus().post(evt); } if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) { - EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundles); + EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundle); MainApp.bus().post(evt); } } @@ -466,13 +447,6 @@ public class DataService extends IntentService { log.debug("Adding/Updating new MBG: " + careportalEvent.log()); } - private void storeSgv(JSONObject sgvJson) { - NSSgv nsSgv = new NSSgv(sgvJson); - BgReading bgReading = new BgReading(nsSgv); - MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); - SourceNSClientPlugin.getPlugin().detectSource(JsonHelper.safeGetString(sgvJson, "device"), JsonHelper.safeGetLong(sgvJson, "mills")); - } - private void handleNewSMS(Intent intent) { Bundle bundle = intent.getExtras(); if (bundle == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java index c6cb7c1b8e..d3d9f1e640 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java @@ -2,9 +2,13 @@ package info.nightscout.androidaps.interfaces; import android.os.Bundle; +import java.util.List; + +import info.nightscout.androidaps.db.BgReading; + /** * Created by mike on 20.06.2016. */ public interface BgSourceInterface { - void processNewData(Bundle bundle); + List processNewData(Bundle bundle); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java index 9327b31754..896782f720 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java @@ -2,12 +2,18 @@ package info.nightscout.androidaps.plugins.Source; import android.os.Bundle; +import com.google.common.collect.Lists; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -47,8 +53,8 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac } @Override - public void processNewData(Bundle bundle) { - BgReading bgReading = new BgReading(); + public List processNewData(Bundle bundle) { + List bgReadings = new ArrayList<>(); String data = bundle.getString("data"); // onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle @@ -59,22 +65,27 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac log.debug("Received Dexcom Data size:" + jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); + BgReading bgReading = new BgReading(); bgReading.value = json.getInt("m_value"); bgReading.direction = json.getString("m_trend"); bgReading.date = json.getLong("m_time") * 1000L; bgReading.raw = 0; bgReading.filtered = true; bgReading.sourcePlugin = SourceDexcomG5Plugin.getPlugin().getName(); - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); - if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); - } - if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + if (isNew) { + bgReadings.add(bgReading); + if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading); + } + if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } } } } catch (JSONException e) { log.error("Unhandled exception", e); } + return bgReadings; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java index a94caa0155..416d51f095 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java @@ -2,6 +2,11 @@ package info.nightscout.androidaps.plugins.Source; import android.os.Bundle; +import com.google.common.collect.Lists; + +import java.util.Collections; +import java.util.List; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; @@ -33,7 +38,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface { } @Override - public void processNewData(Bundle bundle) { + public List processNewData(Bundle bundle) { BgReading bgReading = new BgReading(); bgReading.value = bundle.getDouble("mySGV"); @@ -43,6 +48,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface { bgReading.filtered = false; bgReading.sourcePlugin = SourceGlimpPlugin.getPlugin().getName(); - MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + return isNew ? Lists.newArrayList(bgReading) : Collections.emptyList(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java index 8b7b08e9fb..62bf95bc7c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java @@ -8,6 +8,10 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; @@ -40,11 +44,10 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface } @Override - public void processNewData(Bundle bundle) { - final String collection = bundle.getString("collection"); - if (collection == null) return; + public List processNewData(Bundle bundle) { + List bgReadings = new ArrayList<>(); - if (collection.equals("entries")) { + if (Objects.equals(bundle.getString("collection"), "entries")) { final String data = bundle.getString("data"); if ((data != null) && (data.length() > 0)) { @@ -64,7 +67,10 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface bgReading.filtered = true; bgReading.sourcePlugin = SourceMM640gPlugin.getPlugin().getName(); - MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g"); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + if (isNew) { + bgReadings.add(bgReading); + } break; default: log.debug("Unknown entries type: " + type); @@ -75,5 +81,7 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface } } } + + return bgReadings; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java index 1bd2c3ae7b..1a1081ef6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -2,17 +2,29 @@ package info.nightscout.androidaps.plugins.Source; import android.os.Bundle; +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; /** * Created by mike on 05.08.2016. */ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterface { + private static final Logger log = LoggerFactory.getLogger(SourceNSClientPlugin.class); private static SourceNSClientPlugin plugin = null; @@ -34,8 +46,35 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac } @Override - public void processNewData(Bundle bundle) { - // TODO - throw new IllegalStateException("Nope"); + public List processNewData(Bundle bundle) { + List sgvs = new ArrayList<>(); + try { + if (bundle.containsKey("sgv")) { + String sgvstring = bundle.getString("sgv"); + JSONObject sgvJson = new JSONObject(sgvstring); + BgReading bgReading = new BgReading(new NSSgv(sgvJson)); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + if (isNew) { + sgvs.add(bgReading); + } + } + + if (bundle.containsKey("sgvs")) { + String sgvstring = bundle.getString("sgvs"); + JSONArray jsonArray = new JSONArray(sgvstring); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject sgvJson = jsonArray.getJSONObject(i); + BgReading bgReading = new BgReading(new NSSgv(sgvJson)); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); + if (isNew) { + sgvs.add(bgReading); + } + } + } + } catch (Exception e) { + log.error("Unhandled exception", e); + } + return sgvs; } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java index fc900f38c5..793e367a34 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java @@ -8,6 +8,9 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -47,8 +50,8 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface } @Override - public void processNewData(Bundle bundle) { - BgReading bgReading = new BgReading(); + public List processNewData(Bundle bundle) { + List bgReadings = new ArrayList<>(); String data = bundle.getString("data"); log.debug("Received Poctech Data", data); @@ -58,23 +61,27 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface log.debug("Received Poctech Data size:" + jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); + BgReading bgReading = new BgReading(); bgReading.value = json.getDouble("current"); bgReading.direction = json.getString("direction"); bgReading.date = json.getLong("date"); bgReading.raw = json.getDouble("raw"); if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals("mmol/L")) bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL; - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech"); - if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); - } - if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + if (isNew) { + bgReadings.add(bgReading); + if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading); + } + if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } } } - } catch (JSONException e) { log.error("Unhandled exception", e); } + return bgReadings; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java index 786edb2b49..9dfcf85dd2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.Source; import android.os.Bundle; +import com.google.common.collect.Lists; + +import java.util.Collections; +import java.util.List; import java.util.Objects; import info.nightscout.androidaps.MainApp; @@ -36,7 +40,7 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { } @Override - public void processNewData(Bundle bundle) { + public List processNewData(Bundle bundle) { BgReading bgReading = new BgReading(); bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE); @@ -46,6 +50,7 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { bgReading.sourcePlugin = SourceXdripPlugin.getPlugin().getName(); bgReading.filtered = Objects.equals(bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION), "G5 Native"); - MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP"); + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName()); + return isNew ? Lists.newArrayList(bgReading) : Collections.emptyList(); } }