accept data 1 month back in Dexcom plugin

This commit is contained in:
Milos Kozak 2019-11-20 22:03:31 +01:00
parent 117f56e247
commit 2fe276d101

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.SP
import info.nightscout.androidaps.utils.T
import org.json.JSONObject
import org.slf4j.LoggerFactory
@ -51,7 +52,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
}
fun findDexcomPackageName(): String? {
val packageManager = MainApp.instance().packageManager;
val packageManager = MainApp.instance().packageManager
for (packageInfo in packageManager.getInstalledPackages(0)) {
if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName
}
@ -64,9 +65,9 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
val sensorType = intent.getStringExtra("sensorType") ?: ""
val glucoseValues = intent.getBundleExtra("glucoseValues")
for (i in 0 until glucoseValues.size()) {
val glucoseValue = glucoseValues.getBundle(i.toString())
glucoseValues.getBundle(i.toString())?.let { glucoseValue ->
val bgReading = BgReading()
bgReading.value = glucoseValue!!.getInt("glucoseValue").toDouble()
bgReading.value = glucoseValue.getInt("glucoseValue").toDouble()
bgReading.direction = glucoseValue.getString("trendArrow")
bgReading.date = glucoseValue.getLong("timestamp") * 1000
bgReading.raw = 0.0
@ -79,11 +80,15 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
}
}
}
}
val meters = intent.getBundleExtra("meters")
for (i in 0 until meters.size()) {
val meter = meters.getBundle(i.toString())
val timestamp = meter!!.getLong("timestamp") * 1000
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(timestamp) != null) continue
meter?.let {
val timestamp = it.getLong("timestamp") * 1000
val now = DateUtil.now()
if (timestamp > now - T.months(1).msecs() && timestamp < now)
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(timestamp) == null) {
val jsonObject = JSONObject()
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
jsonObject.put("created_at", DateUtil.toISOString(timestamp))
@ -93,8 +98,13 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
jsonObject.put("units", Constants.MGDL)
NSUpload.uploadCareportalEntryToNS(jsonObject)
}
}
}
if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false) && intent.hasExtra("sensorInsertionTime")) {
val sensorInsertionTime = intent.extras!!.getLong("sensorInsertionTime") * 1000
intent.extras?.let {
val sensorInsertionTime = it.getLong("sensorInsertionTime") * 1000
val now = DateUtil.now()
if (sensorInsertionTime > now - T.months(1).msecs() && sensorInsertionTime < now)
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) {
val jsonObject = JSONObject()
jsonObject.put("enteredBy", "AndroidAPS-Dexcom$sensorType")
@ -103,6 +113,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
NSUpload.uploadCareportalEntryToNS(jsonObject)
}
}
}
} catch (e: Exception) {
log.error("Error while processing intent from Dexcom App", e)
}