From 45bb7997d1e8cf604a44e74dcd2c11653091c8d9 Mon Sep 17 00:00:00 2001 From: christina Date: Sun, 31 Jul 2022 19:34:22 +0300 Subject: [PATCH] intelligo --- .../activities/MyPreferenceFragment.kt | 2 + .../nightscout/androidaps/di/PluginsModule.kt | 15 +- .../plugins/source/BGSourceFragment.kt | 1 + .../plugins/source/IntelligoPlugin.kt | 179 ++++++++++++++++++ app/src/main/res/values-cs-rCZ/strings.xml | 2 + app/src/main/res/values-da-rDK/strings.xml | 2 + app/src/main/res/values-de-rDE/strings.xml | 2 + app/src/main/res/values-lt-rLT/strings.xml | 2 + app/src/main/res/values-no-rNO/strings.xml | 2 + app/src/main/res/values-pl-rPL/strings.xml | 2 + app/src/main/res/values-pt-rPT/strings.xml | 2 + app/src/main/res/values-ro-rRO/strings.xml | 2 + app/src/main/res/values-ru-rRU/strings.xml | 2 + app/src/main/res/values-sk-rSK/strings.xml | 2 + app/src/main/res/values-tr-rTR/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values/strings.xml | 4 + .../userEntry/UserEntryPresentationHelper.kt | 1 + core/src/main/res/drawable/ic_intelligo.xml | 85 +++++++++ .../database/entities/GlucoseValue.kt | 1 + .../androidaps/database/entities/UserEntry.kt | 1 + 21 files changed, 308 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/source/IntelligoPlugin.kt create mode 100644 core/src/main/res/drawable/ic_intelligo.xml diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index 8da9192724..5f928b2eac 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -91,6 +91,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang @Inject lateinit var poctechPlugin: PoctechPlugin @Inject lateinit var tomatoPlugin: TomatoPlugin @Inject lateinit var glunovoPlugin: GlunovoPlugin + @Inject lateinit var intelligoPlugin: IntelligoPlugin @Inject lateinit var aidexPlugin: AidexPlugin @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin @Inject lateinit var statusLinePlugin: StatusLinePlugin @@ -167,6 +168,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang addPreferencesFromResourceIfEnabled(dexcomPlugin, rootKey) addPreferencesFromResourceIfEnabled(tomatoPlugin, rootKey) addPreferencesFromResourceIfEnabled(glunovoPlugin, rootKey) + addPreferencesFromResourceIfEnabled(intelligoPlugin, rootKey) addPreferencesFromResourceIfEnabled(poctechPlugin, rootKey) addPreferencesFromResourceIfEnabled(aidexPlugin, rootKey) addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey) diff --git a/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt index 589a7ea2d4..1805ddb531 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt @@ -368,30 +368,35 @@ abstract class PluginsModule { @AllConfigs @IntoMap @IntKey(470) - abstract fun bindGlunovoPlugin(plugin: GlunovoPlugin): PluginBase + abstract fun bindGlunovoPlugin(plugin: GlunovoPlugin): PluginBase@Binds + + @AllConfigs + @IntoMap + @IntKey(475) + abstract fun bindIntelligoPlugin(plugin: IntelligoPlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(475) + @IntKey(480) abstract fun bindRandomBgPlugin(plugin: RandomBgPlugin): PluginBase // @Binds // @NotNSClient // @IntoMap - // @IntKey(480) + // @IntKey(485) // abstract fun bindOpenHumansPlugin(plugin: OpenHumansUploader): PluginBase @Binds @NotNSClient @IntoMap - @IntKey(480) + @IntKey(490) abstract fun bindsOpenHumansPlugin(plugin: OpenHumansUploader): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(490) + @IntKey(495) abstract fun bindConfigBuilderPlugin(plugin: ConfigBuilderPlugin): PluginBase @Binds diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index a3fd240570..c41e893b49 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -198,6 +198,7 @@ class BGSourceFragment : DaggerFragment() { R.string.poctech -> Sources.PocTech R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo + R.string.intelligo -> Sources.Intelligo R.string.xdrip -> Sources.Xdrip R.string.aidex -> Sources.Aidex else -> Sources.Unknown diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/IntelligoPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/IntelligoPlugin.kt new file mode 100644 index 0000000000..1643d8a843 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/IntelligoPlugin.kt @@ -0,0 +1,179 @@ +package info.nightscout.androidaps.plugins.source + +import android.content.Context +import android.net.Uri +import android.os.Handler +import android.os.HandlerThread +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.R +import info.nightscout.androidaps.database.AppRepository +import info.nightscout.androidaps.database.entities.GlucoseValue +import info.nightscout.androidaps.database.entities.TherapyEvent +import info.nightscout.androidaps.database.entities.UserEntry +import info.nightscout.androidaps.database.entities.ValueWithUnit +import info.nightscout.androidaps.database.transactions.CgmSourceTransaction +import info.nightscout.androidaps.interfaces.BgSource +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.logging.LTag +import info.nightscout.androidaps.logging.UserEntryLogger +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.XDripBroadcast +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.shared.sharedPreferences.SP +import io.reactivex.rxjava3.disposables.CompositeDisposable +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class IntelligoPlugin @Inject constructor( + injector: HasAndroidInjector, + resourceHelper: ResourceHelper, + aapsLogger: AAPSLogger, + private val sp: SP, + private val context: Context, + private val repository: AppRepository, + private val xDripBroadcast: XDripBroadcast, + private val dateUtil: DateUtil, + private val uel: UserEntryLogger, + private val fabricPrivacy: FabricPrivacy +) : PluginBase( + PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment::class.java.name) + .pluginIcon(R.drawable.ic_glunovo) + .pluginName(R.string.intelligo) + .preferencesId(R.xml.pref_bgsource) + .shortName(R.string.intelligo) + .description(R.string.description_source_intelligo), + aapsLogger, resourceHelper, injector +), BgSource { + + private val handler = Handler(HandlerThread(this::class.java.simpleName + "Handler").also { it.start() }.looper) + private lateinit var refreshLoop: Runnable + + private val contentUri: Uri = Uri.parse("content://$AUTHORITY/$TABLE_NAME") + + init { + refreshLoop = Runnable { + try { + handleNewData() + } catch (e: Exception) { + fabricPrivacy.logException(e) + aapsLogger.error("Error while processing data", e) + } + val lastReadTimestamp = sp.getLong(R.string.key_last_processed_intelligo_timestamp, 0L) + val differenceToNow = INTERVAL - (dateUtil.now() - lastReadTimestamp) % INTERVAL + T.secs(10).msecs() + handler.postDelayed(refreshLoop, differenceToNow) + } + } + + private val disposable = CompositeDisposable() + + override fun onStart() { + super.onStart() + handler.postDelayed(refreshLoop, T.secs(30).msecs()) // do not start immediately, app may be still starting + } + + override fun onStop() { + super.onStop() + handler.removeCallbacks(refreshLoop) + disposable.clear() + } + + private fun handleNewData() { + if (!isEnabled()) return + + context.contentResolver.query(contentUri, null, null, null, null)?.let { cr -> + val glucoseValues = mutableListOf() + val calibrations = mutableListOf() + cr.moveToFirst() + + while (!cr.isAfterLast) { + val timestamp = cr.getLong(0) + val value = cr.getDouble(1) //value in mmol/l... + val curr = cr.getDouble(2) + + // bypass already processed + if (timestamp < sp.getLong(R.string.key_last_processed_intelligo_timestamp, 0L)) { + cr.moveToNext() + continue + } + + if (timestamp > dateUtil.now() || timestamp == 0L) { + aapsLogger.error(LTag.BGSOURCE, "Error in received data date/time $timestamp") + cr.moveToNext() + continue + } + + if (value < 2 || value > 25) { + aapsLogger.error(LTag.BGSOURCE, "Error in received data value (value out of bounds) $value") + cr.moveToNext() + continue + } + + if (curr != 0.0) + glucoseValues += CgmSourceTransaction.TransactionGlucoseValue( + timestamp = timestamp, + value = value * Constants.MMOLL_TO_MGDL, + raw = 0.0, + noise = null, + trendArrow = GlucoseValue.TrendArrow.NONE, + sourceSensor = GlucoseValue.SourceSensor.INTELLIGO_NATIVE + ) + else + calibrations.add( + CgmSourceTransaction.Calibration( + timestamp = timestamp, + value = value, + glucoseUnit = TherapyEvent.GlucoseUnit.MMOL + ) + ) + sp.putLong(R.string.key_last_processed_intelligo_timestamp, timestamp) + cr.moveToNext() + } + cr.close() + + if (glucoseValues.isNotEmpty() || calibrations.isNotEmpty()) + repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, calibrations, null)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving values from IntelliGO App", it) + } + .blockingGet() + .also { savedValues -> + savedValues.inserted.forEach { + xDripBroadcast.send(it) + aapsLogger.debug(LTag.DATABASE, "Inserted bg $it") + } + savedValues.calibrationsInserted.forEach { calibration -> + calibration.glucose?.let { glucosevalue -> + uel.log( + UserEntry.Action.CALIBRATION, + UserEntry.Sources.Dexcom, + ValueWithUnit.Timestamp(calibration.timestamp), + ValueWithUnit.TherapyEventType(calibration.type), + ValueWithUnit.fromGlucoseUnit(glucosevalue, calibration.glucoseUnit.toString) + ) + } + aapsLogger.debug(LTag.DATABASE, "Inserted calibration $calibration") + } + } + } + } + + override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean = + glucoseValue.sourceSensor == GlucoseValue.SourceSensor.INTELLIGO_NATIVE && sp.getBoolean(R.string.key_dexcomg5_nsupload, false) + + companion object { + + @Suppress("SpellCheckingInspection") + const val AUTHORITY = "alexpr.co.uk.infinivocgm.intelligo.provider/" + const val TABLE_NAME = "CgmReading" + const val INTERVAL = 180000L // 3 min + } +} diff --git a/app/src/main/res/values-cs-rCZ/strings.xml b/app/src/main/res/values-cs-rCZ/strings.xml index 0d8a78f482..720897882e 100644 --- a/app/src/main/res/values-cs-rCZ/strings.xml +++ b/app/src/main/res/values-cs-rCZ/strings.xml @@ -656,6 +656,8 @@ Získávat glykémie z aplikace Poctech Glunovo Získávat glykémie z aplikace Glunovo + Intelligo + Získávat glykémie z aplikace Intelligo Přijímat hodnoty glykémií z Tomato aplikace (MiaoMiao zařízení) Vysoký dočasný cíl zvýší senzitivitu = 5.5]]> diff --git a/app/src/main/res/values-da-rDK/strings.xml b/app/src/main/res/values-da-rDK/strings.xml index b21dfe69b3..c2c5332077 100644 --- a/app/src/main/res/values-da-rDK/strings.xml +++ b/app/src/main/res/values-da-rDK/strings.xml @@ -647,6 +647,8 @@ Modtag BS-værdier fra Poctech app Glunovo Modtag værdier fra Glunovo app + Intelligo + Modtag værdier fra Intelligo app Modtag BS-værdier fra Tomato-appen (MiaoMiao enhed) Høj midlertidig basal øger sensitivitet = 100]]> diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 43c2f5b311..94a6d1e3ed 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -642,6 +642,8 @@ Verstrichene Zeit Poctech Empfange Blutzucker-Werte von der Poctech-App. + Intelligo + Werte von der Intelligo App erhalten Glunovo Werte von der Glunovo App erhalten Empfange Blutzucker-Werte von der Tomato-App (MiaoMiao-Geräte) diff --git a/app/src/main/res/values-lt-rLT/strings.xml b/app/src/main/res/values-lt-rLT/strings.xml index dcf41407e5..5940ad2968 100644 --- a/app/src/main/res/values-lt-rLT/strings.xml +++ b/app/src/main/res/values-lt-rLT/strings.xml @@ -642,6 +642,8 @@ Gauti KG vertes iš Poctech programėlės Glunovo Gauti KG reikšmes iš Glunovo programos + Intelligo + Gauti KG reikšmes iš Intelligo programos Gauti KG vertes iš Tomato programėlės (MiaoMiao) Intensyvus laikinas tikslas didina jautrumą = 100]]> diff --git a/app/src/main/res/values-no-rNO/strings.xml b/app/src/main/res/values-no-rNO/strings.xml index b485585ece..06dc71b016 100644 --- a/app/src/main/res/values-no-rNO/strings.xml +++ b/app/src/main/res/values-no-rNO/strings.xml @@ -656,6 +656,8 @@ Motta BS verdier fra Poctech app Glunovo Motta BS verdier fra Glunovo app + Intelligo + Motta BS verdier fra Intelligo app Motta BS verdier fra Tomato app (MiaoMiao enhet) Høy temp target øker sensitiviteten = 100]]> diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml index f91047c74f..b17d0ded19 100644 --- a/app/src/main/res/values-pl-rPL/strings.xml +++ b/app/src/main/res/values-pl-rPL/strings.xml @@ -643,6 +643,8 @@ Odczytuj wartości BG z aplikacji Poctech Glunovo Otrzymuj wartości z aplikacji Glunovo + Intelligo + Otrzymuj wartości z aplikacji Intelligo Otrzymuj poziomy cukru (BG) z Apki Tomato) (urządzenie MiaoMiao) Wysoki tymczasowy cel zwiększy wrażliwość = 100]]> diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index b435fbeb69..e5dd09a500 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -642,6 +642,8 @@ Receber valores Glucose da app Poctech Glunovo Receber valores do aplicativo Glunovo + Intelligo + Receber valores do aplicativo Intelligo Receber valores de Glicose da app Tomato (dispositivo MiaoMiao) Alto alvotempo aumenta sensibilidade = 100]]> diff --git a/app/src/main/res/values-ro-rRO/strings.xml b/app/src/main/res/values-ro-rRO/strings.xml index 44c5283a22..3bf72a17ea 100644 --- a/app/src/main/res/values-ro-rRO/strings.xml +++ b/app/src/main/res/values-ro-rRO/strings.xml @@ -642,6 +642,8 @@ Citire a valorii glicemiei din aplicația Poctech Glunovo Primiți glicemii de la aplicația Glunovo + Intelligo + Primiți glicemii de la aplicația Intelligo Înregistrează valorile glicemiei din aplicația Tomato (dispozitiv MiaoMIao) Ținte temporare mai mari cresc sensibilitatea = 100]]> diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 76c70619d1..48dd372d97 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -656,6 +656,8 @@ Получать данные гликемии от приложения Poctech Приложение Glunovo Получать данные гликемии от приложения Glunovo + Приложение Intelligo + Получать данные гликемии от приложения Intelligo Получать значения ГК от приложения Tomato (устройство MiaoMiao) Высокая врем. цель temptarget повышает чувствительность = 100]]> diff --git a/app/src/main/res/values-sk-rSK/strings.xml b/app/src/main/res/values-sk-rSK/strings.xml index 5173d5ea18..6647753970 100644 --- a/app/src/main/res/values-sk-rSK/strings.xml +++ b/app/src/main/res/values-sk-rSK/strings.xml @@ -656,6 +656,8 @@ Získavať glykémie z aplikácie Poctech Glunovo Získavať glykémie z aplikácie Glunovo + Intelligo + Získavať glykémie z aplikácie Intelligo Prijímať glykémie z aplikácie Tomato (zariadenie MiaoMiao) Vysoký dočasný cieľ zvýši citlivosť = 5.5]]> diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index ee47a75e18..3a9f281f95 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -657,6 +657,8 @@ Aktif Karbonhidratın ne kadar hızlı sindirildiğine ve KŞ\'nin beklenenden d Poctech uygulamasından KŞ değerlerini alır Glunovo Glunovo uygulamasından değerler alır + Intelligo + Intelligo uygulamasından değerler alır KŞ değerlerini Tomato uygulamasından (MiaoMiao Cihazından) al Yüksek geçici hedefler duyarlılığı artırır = 100]]> diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 47018ea425..1bc7867963 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -648,6 +648,8 @@ 从 Poctech app 接收血糖值。 Glunovo 从Glunovo应用接收血糖数据。 + Intelligo + 从Intelligo应用接收血糖数据。 从番茄app(喵喵设备) 接收血糖值 高临时目标增加灵敏度 =100 mg/dl (5.5 mmol/l) 时提高灵敏度]]> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 148a476141..d4e11fa7fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -800,6 +800,8 @@ Receive BG values from Poctech app Glunovo Receive values from Glunovo app + Intelligo + Receive values from Intelligo app Receive BG values from Tomato app (MiaoMiao device) high_temptarget_raises_sensitivity low_temptarget_lowers_sensitivity @@ -1125,6 +1127,8 @@ Recalculated data used BG too close:\n%1$s\n%2$s last_processed_glunovo_timestamp + + last_processed_intelligo_timestamp Identification (email, FB or Discord nick etc) Identification not set in dev mode dialog diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index faae359445..2cc1a020f2 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -73,6 +73,7 @@ class UserEntryPresentationHelper @Inject constructor( Sources.PocTech -> R.drawable.ic_poctech Sources.Tomato -> R.drawable.ic_sensor Sources.Glunovo -> R.drawable.ic_glunovo + Sources.Intelligo -> R.drawable.ic_intelligo Sources.Xdrip -> R.drawable.ic_blooddrop_48 Sources.LocalProfile -> R.drawable.ic_local_profile Sources.Loop -> R.drawable.ic_loop_closed_white diff --git a/core/src/main/res/drawable/ic_intelligo.xml b/core/src/main/res/drawable/ic_intelligo.xml new file mode 100644 index 0000000000..6fe7de817b --- /dev/null +++ b/core/src/main/res/drawable/ic_intelligo.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt index 00979a554c..5906caad5b 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt @@ -109,6 +109,7 @@ data class GlucoseValue( LIBRE_2_NATIVE("Libre2"), POCTECH_NATIVE("Poctech"), GLUNOVO_NATIVE("Glunovo"), + INTELLIGO_NATIVE("Intelligo"), MM_600_SERIES("MM600Series"), EVERSENSE("Eversense"), AIDEX("GlucoRx Aidex"), diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt index 23c659c5c2..161b7fffe4 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt @@ -149,6 +149,7 @@ data class UserEntry( PocTech, Tomato, Glunovo, + Intelligo, Xdrip, LocalProfile, //From LocalProfile plugin Loop, //From Loop plugin