Merge remote-tracking branch 'ns/dev' into newdb
This commit is contained in:
commit
9cade8f422
6 changed files with 37 additions and 33 deletions
|
@ -13,6 +13,7 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.receivers.BundleStore;
|
import info.nightscout.androidaps.receivers.BundleStore;
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||||
|
|
||||||
// cannot be inner class because of needed injection
|
// cannot be inner class because of needed injection
|
||||||
public class NSClientWorker extends Worker {
|
public class NSClientWorker extends Worker {
|
||||||
|
@ -30,9 +31,9 @@ public class NSClientWorker extends Worker {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Result doWork() {
|
public Result doWork() {
|
||||||
Bundle bundle = bundleStore.pickup(getInputData().getLong("storeKey", -1));
|
Bundle bundle = bundleStore.pickup(getInputData().getLong(DataReceiver.STORE_KEY, -1));
|
||||||
if (bundle == null) Result.failure();
|
if (bundle == null) return Result.failure();
|
||||||
String action = getInputData().getString("action");
|
String action = getInputData().getString(DataReceiver.ACTION_KEY);
|
||||||
nsClientPlugin.handleNewDataFromNSClient(action, bundle);
|
nsClientPlugin.handleNewDataFromNSClient(action, bundle);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.receivers.BundleStore
|
import info.nightscout.androidaps.receivers.BundleStore
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.*
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
@ -172,7 +173,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
|
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
|
||||||
?: return Result.failure()
|
?: return Result.failure()
|
||||||
val format = bundle.getString("format") ?: return Result.failure()
|
val format = bundle.getString("format") ?: return Result.failure()
|
||||||
val pdus = bundle["pdus"] as Array<*>
|
val pdus = bundle["pdus"] as Array<*>
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.receivers.BundleStore
|
import info.nightscout.androidaps.receivers.BundleStore
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.XDripBroadcast
|
import info.nightscout.androidaps.utils.XDripBroadcast
|
||||||
|
@ -92,7 +93,7 @@ class DexcomPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
if (!dexcomPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
if (!dexcomPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
||||||
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
|
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
|
||||||
?: return Result.failure()
|
?: return Result.failure()
|
||||||
try {
|
try {
|
||||||
val sourceSensor = when (bundle.getString("sensorType") ?: "") {
|
val sourceSensor = when (bundle.getString("sensorType") ?: "") {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.receivers.BundleStore
|
import info.nightscout.androidaps.receivers.BundleStore
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.XDripBroadcast
|
import info.nightscout.androidaps.utils.XDripBroadcast
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
@ -78,7 +79,7 @@ class EversensePlugin @Inject constructor(
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
if (!eversensePlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
if (!eversensePlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
||||||
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
|
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
|
||||||
?: return Result.failure()
|
?: return Result.failure()
|
||||||
if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase"))
|
if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase"))
|
||||||
if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress"))
|
if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress"))
|
||||||
|
|
|
@ -14,6 +14,8 @@ import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
import info.nightscout.androidaps.receivers.BundleStore
|
||||||
|
import info.nightscout.androidaps.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.services.Intents
|
import info.nightscout.androidaps.services.Intents
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
@ -67,6 +69,7 @@ class XdripPlugin @Inject constructor(
|
||||||
|
|
||||||
@Inject lateinit var xdripPlugin: XdripPlugin
|
@Inject lateinit var xdripPlugin: XdripPlugin
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
@Inject lateinit var bundleStore: BundleStore
|
||||||
|
|
||||||
init {
|
init {
|
||||||
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
||||||
|
@ -74,15 +77,18 @@ class XdripPlugin @Inject constructor(
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
if (!xdripPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
if (!xdripPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
|
||||||
xdripPlugin.aapsLogger.debug(LTag.BGSOURCE, "Received xDrip data: $inputData")
|
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
|
||||||
|
?: return Result.failure()
|
||||||
|
|
||||||
|
xdripPlugin.aapsLogger.debug(LTag.BGSOURCE, "Received xDrip data: $bundle")
|
||||||
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
|
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
|
||||||
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
|
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
|
||||||
timestamp = inputData.getLong(Intents.EXTRA_TIMESTAMP, 0),
|
timestamp = bundle.getLong(Intents.EXTRA_TIMESTAMP, 0),
|
||||||
value = inputData.getDouble(Intents.EXTRA_BG_ESTIMATE, 0.0),
|
value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE, 0.0),
|
||||||
raw = inputData.getDouble(Intents.EXTRA_RAW, 0.0),
|
raw = bundle.getDouble(Intents.EXTRA_RAW, 0.0),
|
||||||
noise = null,
|
noise = null,
|
||||||
trendArrow = GlucoseValue.TrendArrow.fromString(inputData.getString(Intents.EXTRA_BG_SLOPE_NAME)),
|
trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.EXTRA_BG_SLOPE_NAME)),
|
||||||
sourceSensor = GlucoseValue.SourceSensor.fromString(inputData.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION)
|
sourceSensor = GlucoseValue.SourceSensor.fromString(bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION)
|
||||||
?: "")
|
?: "")
|
||||||
)
|
)
|
||||||
xdripPlugin.disposable += repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)).subscribe({ savedValues ->
|
xdripPlugin.disposable += repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)).subscribe({ savedValues ->
|
||||||
|
@ -92,7 +98,7 @@ class XdripPlugin @Inject constructor(
|
||||||
}, {
|
}, {
|
||||||
xdripPlugin.aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Eversense App", it)
|
xdripPlugin.aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Eversense App", it)
|
||||||
})
|
})
|
||||||
xdripPlugin.sensorBatteryLevel = inputData.getInt(Intents.EXTRA_SENSOR_BATTERY, -1)
|
xdripPlugin.sensorBatteryLevel = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY, -1)
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import androidx.work.Data
|
import androidx.work.Data
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
|
@ -39,10 +40,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intents.ACTION_NEW_BG_ESTIMATE ->
|
Intents.ACTION_NEW_BG_ESTIMATE ->
|
||||||
OneTimeWorkRequest.Builder(XdripPlugin.XdripWorker::class.java)
|
OneTimeWorkRequest.Builder(XdripPlugin.XdripWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(bundleInputData(bundle, intent)).build()
|
||||||
it.copyString("collection", bundle, null)
|
|
||||||
it.copyString("data", bundle)
|
|
||||||
}.build()).build()
|
|
||||||
Intents.POCTECH_BG ->
|
Intents.POCTECH_BG ->
|
||||||
OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java)
|
OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(Data.Builder().also {
|
||||||
|
@ -84,36 +82,32 @@ open class DataReceiver : DaggerBroadcastReceiver() {
|
||||||
}.build()).build()
|
}.build()).build()
|
||||||
Telephony.Sms.Intents.SMS_RECEIVED_ACTION ->
|
Telephony.Sms.Intents.SMS_RECEIVED_ACTION ->
|
||||||
OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java)
|
OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(bundleInputData(bundle, intent)).build()
|
||||||
it.putLong("storeKey", bundleStore.store(bundle))
|
|
||||||
it.putString("action", intent.action)
|
|
||||||
}.build()).build()
|
|
||||||
Intents.EVERSENSE_BG ->
|
Intents.EVERSENSE_BG ->
|
||||||
OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java)
|
OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(bundleInputData(bundle, intent)).build()
|
||||||
it.putLong("storeKey", bundleStore.store(bundle))
|
|
||||||
it.putString("action", intent.action)
|
|
||||||
}.build()).build()
|
|
||||||
Intents.DEXCOM_BG ->
|
Intents.DEXCOM_BG ->
|
||||||
OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java)
|
OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(bundleInputData(bundle, intent)).build()
|
||||||
it.putLong("storeKey", bundleStore.store(bundle))
|
|
||||||
it.putString("action", intent.action)
|
|
||||||
}.build()).build()
|
|
||||||
Intents.ACTION_NEW_TREATMENT,
|
Intents.ACTION_NEW_TREATMENT,
|
||||||
Intents.ACTION_CHANGED_TREATMENT,
|
Intents.ACTION_CHANGED_TREATMENT,
|
||||||
Intents.ACTION_REMOVED_TREATMENT,
|
Intents.ACTION_REMOVED_TREATMENT,
|
||||||
Intents.ACTION_NEW_CAL,
|
Intents.ACTION_NEW_CAL,
|
||||||
Intents.ACTION_NEW_MBG ->
|
Intents.ACTION_NEW_MBG ->
|
||||||
OneTimeWorkRequest.Builder(NSClientWorker::class.java)
|
OneTimeWorkRequest.Builder(NSClientWorker::class.java)
|
||||||
.setInputData(Data.Builder().also {
|
.setInputData(bundleInputData(bundle, intent)).build()
|
||||||
it.putLong("storeKey", bundleStore.store(bundle))
|
|
||||||
it.putString("action", intent.action)
|
|
||||||
}.build()).build()
|
|
||||||
else -> null
|
else -> null
|
||||||
}?.let { request ->
|
}?.let { request ->
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniqueWork(jobGroupName, ExistingWorkPolicy.APPEND_OR_REPLACE , request)
|
.enqueueUniqueWork(jobGroupName, ExistingWorkPolicy.APPEND_OR_REPLACE , request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bundleInputData(bundle: Bundle, intent: Intent) =
|
||||||
|
Data.Builder().putLong(STORE_KEY, bundleStore.store(bundle)).putString(ACTION_KEY, intent.action).build()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val STORE_KEY = "storeKey"
|
||||||
|
const val ACTION_KEY = "action"
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue