From b870de1e078696a842b934287edf09c7754b313d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 11 Oct 2023 21:09:57 +0200 Subject: [PATCH 1/5] NSCv3: improve WS connection --- .../plugins/sync/nsShared/NSClientFragment.kt | 4 +- .../events/EventConnectivityOptionChanged.kt | 2 +- .../plugins/sync/nsclient/ReceiverDelegate.kt | 2 +- .../sync/nsclientV3/NSClientV3Plugin.kt | 86 +++++++++++-------- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/NSClientFragment.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/NSClientFragment.kt index b3b0d61e12..25a2d0eb3a 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/NSClientFragment.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/NSClientFragment.kt @@ -122,6 +122,8 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment { ID_MENU_CLEAR_LOG -> { nsClientPlugin?.listLog?.let { synchronized(it) { + val size = it.size + binding.recyclerview.adapter?.notifyItemRangeRemoved(0, size) it.clear() updateLog() } @@ -135,7 +137,7 @@ class NSClientFragment : DaggerFragment(), MenuProvider, PluginFragment { } ID_MENU_SEND_NOW -> { - nsClientPlugin?.resend("GUI") + handler.post { nsClientPlugin?.resend("GUI") } true } diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/events/EventConnectivityOptionChanged.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/events/EventConnectivityOptionChanged.kt index eabc9b4813..4240e5ce85 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/events/EventConnectivityOptionChanged.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsShared/events/EventConnectivityOptionChanged.kt @@ -2,4 +2,4 @@ package app.aaps.plugins.sync.nsShared.events import app.aaps.core.interfaces.rx.events.Event -class EventConnectivityOptionChanged(val blockingReason: String) : Event() \ No newline at end of file +class EventConnectivityOptionChanged(val blockingReason: String, val connected: Boolean) : Event() \ No newline at end of file diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclient/ReceiverDelegate.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclient/ReceiverDelegate.kt index cf20d81516..cceb6490f0 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclient/ReceiverDelegate.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclient/ReceiverDelegate.kt @@ -94,7 +94,7 @@ class ReceiverDelegate @Inject constructor( if (newAllowedState != allowed) { allowed = newAllowedState if (allowed) blockingReason = "" - rxBus.send(EventConnectivityOptionChanged(blockingReason)) + rxBus.send(EventConnectivityOptionChanged(blockingReason, receiverStatusStore.isConnected)) } } diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt index ae351b9260..66432b7e78 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -156,16 +156,16 @@ class NSClientV3Plugin @Inject constructor( override val status get() = when { - sp.getBoolean(R.string.key_ns_paused, false) -> rh.gs(app.aaps.core.ui.R.string.paused) - isAllowed.not() -> blockingReason + sp.getBoolean(R.string.key_ns_paused, false) -> rh.gs(app.aaps.core.ui.R.string.paused) + isAllowed.not() -> blockingReason sp.getBoolean(app.aaps.core.utils.R.string.key_ns_use_ws, true) && wsConnected -> "WS: " + rh.gs(app.aaps.core.interfaces.R.string.connected) sp.getBoolean(app.aaps.core.utils.R.string.key_ns_use_ws, true) && !wsConnected -> "WS: " + rh.gs(R.string.not_connected) - lastOperationError != null -> rh.gs(app.aaps.core.ui.R.string.error) - nsAndroidClient?.lastStatus == null -> rh.gs(R.string.not_connected) - workIsRunning() -> rh.gs(R.string.working) - nsAndroidClient?.lastStatus?.apiPermissions?.isFull() == true -> rh.gs(app.aaps.core.interfaces.R.string.connected) - nsAndroidClient?.lastStatus?.apiPermissions?.isRead() == true -> rh.gs(R.string.read_only) - else -> rh.gs(app.aaps.core.ui.R.string.unknown) + lastOperationError != null -> rh.gs(app.aaps.core.ui.R.string.error) + nsAndroidClient?.lastStatus == null -> rh.gs(R.string.not_connected) + workIsRunning() -> rh.gs(R.string.working) + nsAndroidClient?.lastStatus?.apiPermissions?.isFull() == true -> rh.gs(app.aaps.core.interfaces.R.string.connected) + nsAndroidClient?.lastStatus?.apiPermissions?.isRead() == true -> rh.gs(R.string.read_only) + else -> rh.gs(app.aaps.core.ui.R.string.unknown) } var lastOperationError: String? = null @@ -197,8 +197,13 @@ class NSClientV3Plugin @Inject constructor( .observeOn(aapsSchedulers.io) .subscribe({ ev -> rxBus.send(EventNSClientNewLog("● CONNECTIVITY", ev.blockingReason)) - setClient("CONNECTIVITY") - if (isAllowed) executeLoop("CONNECTIVITY", forceNew = false) + if (ev.connected) { + when { + isAllowed && storageSocket == null -> setClient("CONNECTIVITY") // socket must be created + !isAllowed && storageSocket != null -> shutdownWebsockets() + } + if (isAllowed) executeLoop("CONNECTIVITY", forceNew = false) + } rxBus.send(EventNSClientUpdateGuiStatus()) }, fabricPrivacy::logException) disposable += rxBus @@ -211,8 +216,10 @@ class NSClientV3Plugin @Inject constructor( ev.isChanged(rh.gs(R.string.key_ns_paused)) || ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_ns_alarms)) || ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_ns_announcements)) - ) + ) { + shutdownWebsockets() setClient("SETTING CHANGE") + } if (ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_local_profile_last_change))) executeUpload("PROFILE_CHANGE", forceNew = true) @@ -299,10 +306,7 @@ class NSClientV3Plugin @Inject constructor( override fun onStop() { handler.removeCallbacksAndMessages(null) disposable.clear() - storageSocket?.disconnect() - alarmSocket?.disconnect() - storageSocket = null - alarmSocket = null + shutdownWebsockets() super.onStop() } @@ -331,19 +335,14 @@ class NSClientV3Plugin @Inject constructor( } private fun setClient(reason: String) { - nsAndroidClient = NSAndroidClientImpl( - baseUrl = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace("https://", "").replace(Regex("/$"), ""), - accessToken = sp.getString(R.string.key_ns_client_token, ""), - context = context, - logging = true, - logger = { msg -> aapsLogger.debug(LTag.HTTP, msg) } - ) - if (wsConnected) { - storageSocket?.disconnect() - alarmSocket?.disconnect() - storageSocket = null - alarmSocket = null - } + if (nsAndroidClient == null) + nsAndroidClient = NSAndroidClientImpl( + baseUrl = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace("https://", "").replace(Regex("/$"), ""), + accessToken = sp.getString(R.string.key_ns_client_token, ""), + context = context, + logging = config.isEngineeringMode() || config.isDev(), + logger = { msg -> aapsLogger.debug(LTag.HTTP, msg) } + ) SystemClock.sleep(2000) initializeWebSockets(reason) rxBus.send(EventSWSyncStatus(status)) @@ -354,8 +353,28 @@ class NSClientV3Plugin @Inject constructor( **********************/ private var storageSocket: Socket? = null private var alarmSocket: Socket? = null - var wsConnected = false + internal var wsConnected = false internal var initialLoadFinished = false + + private fun shutdownWebsockets() { + storageSocket?.on(Socket.EVENT_CONNECT, onConnectStorage) + storageSocket?.on(Socket.EVENT_DISCONNECT, onDisconnectStorage) + storageSocket?.on("create", onDataCreateUpdate) + storageSocket?.on("update", onDataCreateUpdate) + storageSocket?.on("delete", onDataDelete) + storageSocket?.disconnect() + alarmSocket?.on(Socket.EVENT_CONNECT, onConnectAlarms) + alarmSocket?.on(Socket.EVENT_DISCONNECT, onDisconnectAlarm) + alarmSocket?.on("announcement", onAnnouncement) + alarmSocket?.on("alarm", onAlarm) + alarmSocket?.on("urgent_alarm", onUrgentAlarm) + alarmSocket?.on("clear_alarm", onClearAlarm) + alarmSocket?.disconnect() + wsConnected = false + storageSocket = null + alarmSocket = null + } + private fun initializeWebSockets(reason: String) { if (!sp.getBoolean(app.aaps.core.utils.R.string.key_ns_use_ws, true)) return if (sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").isEmpty()) return @@ -435,13 +454,8 @@ class NSClientV3Plugin @Inject constructor( rxBus.send(EventNSClientNewLog("► WS", "requesting auth for alarms")) socket.emit("subscribe", authMessage, Ack { args -> val response = args[0] as JSONObject - wsConnected = if (response.optBoolean("success")) { - rxBus.send(EventNSClientNewLog("◄ WS", response.optString("message"))) - true - } else { - rxBus.send(EventNSClientNewLog("◄ WS", "Auth failed")) - false - } + if (response.optBoolean("success")) rxBus.send(EventNSClientNewLog("◄ WS", response.optString("message"))) + else rxBus.send(EventNSClientNewLog("◄ WS", "Auth failed")) }) } } From 6b747d40f8f694d9f83b508069af8c9f42ac91ae Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 11 Oct 2023 21:19:55 +0200 Subject: [PATCH 2/5] Automation: periodic 1 -> 2.5 min --- .../main/kotlin/app/aaps/plugins/automation/AutomationPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/automation/src/main/kotlin/app/aaps/plugins/automation/AutomationPlugin.kt b/plugins/automation/src/main/kotlin/app/aaps/plugins/automation/AutomationPlugin.kt index 89e821b52b..64a3a11bd5 100644 --- a/plugins/automation/src/main/kotlin/app/aaps/plugins/automation/AutomationPlugin.kt +++ b/plugins/automation/src/main/kotlin/app/aaps/plugins/automation/AutomationPlugin.kt @@ -129,7 +129,7 @@ class AutomationPlugin @Inject constructor( init { refreshLoop = Runnable { processActions() - handler.postDelayed(refreshLoop, T.mins(1).msecs()) + handler.postDelayed(refreshLoop, T.secs(150).msecs()) } } From 06cf2376d79db83e67d2cb5b138ad294df0507fd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Oct 2023 15:53:45 +0200 Subject: [PATCH 3/5] suppress ExperimentalUnsignedTypes warning --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index a1c8bd34cb..44a644c1b0 100644 --- a/build.gradle +++ b/build.gradle @@ -97,6 +97,7 @@ allprojects { kotlinOptions { freeCompilerArgs = [ '-opt-in=kotlin.RequiresOptIn', + '-opt-in=kotlin.ExperimentalUnsignedTypes', '-Xjvm-default=all' //Support @JvmDefault ] jvmTarget = "11" From 53efb176be101e8ecc4f1c91611ab5819303d13c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Oct 2023 15:54:55 +0200 Subject: [PATCH 4/5] New Crowdin updates (#2902) * New translations strings.xml (Spanish) * New translations strings.xml (Norwegian Bokmal) * New translations strings.xml (Dutch) * New translations strings.xml (Norwegian Bokmal) * New translations strings.xml (Norwegian Bokmal) * New translations strings.xml (Czech) * New translations strings.xml (Norwegian Bokmal) * New translations strings.xml (Dutch) --- plugins/source/src/main/res/values-nb-rNO/strings.xml | 1 + pump/medtrum/src/main/res/values-cs-rCZ/strings.xml | 3 +++ pump/medtrum/src/main/res/values-es-rES/strings.xml | 3 +++ pump/medtrum/src/main/res/values-nb-rNO/strings.xml | 3 +++ pump/medtrum/src/main/res/values-nl-rNL/strings.xml | 3 +++ pump/omnipod-common/src/main/res/values-nb-rNO/strings.xml | 4 ++-- pump/omnipod-eros/src/main/res/values-nb-rNO/strings.xml | 2 +- 7 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/source/src/main/res/values-nb-rNO/strings.xml b/plugins/source/src/main/res/values-nb-rNO/strings.xml index 7c3822f36a..f943044097 100644 --- a/plugins/source/src/main/res/values-nb-rNO/strings.xml +++ b/plugins/source/src/main/res/values-nb-rNO/strings.xml @@ -34,5 +34,6 @@ I xDrip+, velg 640G/Eversens som datakilde Innstillinger for opplasting av BS Logg sensorbytte til NS + Opprett hendelse \"Sensorbytte\" automatisk i NS ved start av sensoren retning diff --git a/pump/medtrum/src/main/res/values-cs-rCZ/strings.xml b/pump/medtrum/src/main/res/values-cs-rCZ/strings.xml index 3bd036a325..1493204dbf 100644 --- a/pump/medtrum/src/main/res/values-cs-rCZ/strings.xml +++ b/pump/medtrum/src/main/res/values-cs-rCZ/strings.xml @@ -53,6 +53,7 @@ Vybitá baterie Žádná kalibrace Nepodařilo se aktualizovat časové pásmo pumpy, odložit zprávu a aktualizovat ručně. + Chyba bolusu Opakovat Další @@ -101,6 +102,8 @@ Stiskněte Další pro obnovení aktivace nebo Zahodit pro resetování stavu aktivace. Počkejte prosím, čtení stavu aktivace z Patche. + Výstraha při nedostupné pumpě byla vynucena, protože patch pumpa Medtrum může selhat a být nedostupná. + Doporučujeme nastavit na 30 minut, protože patch pumpa Medtrum může selhat a být nedostupná. Sériové číslo Zadejte sériové číslo základny Patche. Neplatné sériové číslo! diff --git a/pump/medtrum/src/main/res/values-es-rES/strings.xml b/pump/medtrum/src/main/res/values-es-rES/strings.xml index 50534174b7..c8c013cc15 100644 --- a/pump/medtrum/src/main/res/values-es-rES/strings.xml +++ b/pump/medtrum/src/main/res/values-es-rES/strings.xml @@ -53,6 +53,7 @@ Batería agotada Sin calibración Error al actualizar la zona horaria de la bomba, posponer zumbido y actualizar manualmente. + Error de bolo Reintentar Siguiente @@ -101,6 +102,8 @@ Presiona Siguiente para reanudar la activación o Descartar para restablecer el estado de activación. Por favor, espera, leyendo el estado de activación de la bomba. + Se ha habilitado la alerta de \"Inaccesible forzada\" debido a la posibilidad de que el parche de Medtrum falle y no pueda ser contactado. + Se recomienda configurarlo a 30 minutos, debido a que el parche de Medtrum puede presentar fallos y quedar inaccesible. Número de serie Introduce el número de serie de la base de la bomba. ¡Número de serie inválido! diff --git a/pump/medtrum/src/main/res/values-nb-rNO/strings.xml b/pump/medtrum/src/main/res/values-nb-rNO/strings.xml index b2f4013796..c72e66c4d5 100644 --- a/pump/medtrum/src/main/res/values-nb-rNO/strings.xml +++ b/pump/medtrum/src/main/res/values-nb-rNO/strings.xml @@ -53,6 +53,7 @@ Batteri er tatt ut Ingen kalibrering Kunne ikke oppdatere tidssone på pumpen. Bekreft meldingen og oppdater manuelt. + Bolus feilet Prøv igjen Neste @@ -101,6 +102,8 @@ Trykk Neste for å gjenoppta aktiveringen eller Forkast for å tilbakestille aktiveringsstatusen. Vennligst vent, leser aktiveringsstatus fra pumpen. + Varsel om pumpe utilgjengelig tvinges aktivert, fordi Medtrum-patching kan mislykkes og bli utilgjengelig. + Anbefales å sette til 30 minutter, fordi Medtrum-patching kan mislykkes og bli utilgjengelig. Serienummer Skriv inn serienummeret til pumpens base. Ugyldig serienummer! diff --git a/pump/medtrum/src/main/res/values-nl-rNL/strings.xml b/pump/medtrum/src/main/res/values-nl-rNL/strings.xml index a55cf9a280..1695ea051f 100644 --- a/pump/medtrum/src/main/res/values-nl-rNL/strings.xml +++ b/pump/medtrum/src/main/res/values-nl-rNL/strings.xml @@ -101,6 +101,8 @@ Druk op Volgende om de activering te hervatten of Verwijderen om de activeringsstatus te resetten. Een ogenblik geduld, activeringsstatus van de pomp wordt gelezen. + Waarschuwing onbereikbare pump geforceerd ingeschakeld, omdat de Medtrum-patch kan falen en onbereikbaar kan zijn. + Geadviseerd om op 30 minuten in te stellen, omdat de Medtrum-patch kan falen en onbereikbaar kan zijn. Serienummer Voer het serienummer van uw pompbasis in. Ongeldig serienummer! @@ -108,6 +110,7 @@ Alarminstellingen Selecteer uw gewenste alarminstellingen voor de pomp. Notificatie bij pomp waarschuwing + Melding weergeven op niet-kritische pompwaarschuwingen: batterij bijna leeg, reservoir bijna leeg (20 eenheden) en vervalt bijna. Aanbevolen om ingeschakeld te laten wanneer pomp alarmen op stil zijn ingesteld. Patch vervalt Wanneer ingeschakeld, zal de patch na 3 dagen verlopen met een extra periode van 8 uur coulance. Maximale insuline per uur diff --git a/pump/omnipod-common/src/main/res/values-nb-rNO/strings.xml b/pump/omnipod-common/src/main/res/values-nb-rNO/strings.xml index ebd443fd13..6682ce3e14 100644 --- a/pump/omnipod-common/src/main/res/values-nb-rNO/strings.xml +++ b/pump/omnipod-common/src/main/res/values-nb-rNO/strings.xml @@ -106,9 +106,9 @@ Utløpspåminnelse aktivert Når aktivert, vil Pod\'en pipe når tidspunktet er nådd Påminnelse før utløp (72 timer) - Utløpspåminnelse aktivert + Nedstengingspåminnelse aktivert Når aktivert, vil Pod\'en pipe når tidspunktet er nådd og en time før nedstenging - Påminnelse før utløp (80 timer) + Påminnelse før nedstenging (80 timer) Varsel om lavt reservoar aktivert Antall enheter Demp Pod-varsler automatisk diff --git a/pump/omnipod-eros/src/main/res/values-nb-rNO/strings.xml b/pump/omnipod-eros/src/main/res/values-nb-rNO/strings.xml index d2277396ce..ba11108eea 100644 --- a/pump/omnipod-eros/src/main/res/values-nb-rNO/strings.xml +++ b/pump/omnipod-eros/src/main/res/values-nb-rNO/strings.xml @@ -52,7 +52,7 @@ Endring av tid mislyktes. Insulinlevering er pauset! Velg gjenoppta levering manuelt fra Omnipod-fanen. Feilet i å lese Pulsloggen Feilet i forsøket på å endre tid på Pod. Du må gå inn i Omnipod menyen og manuelt synkronisere tiden. - Operasjon ikke mulig.\n\n Du må konfigurere Medtronic pumpen før du kan bruke denne funksjonen. + Operasjon ikke mulig.\n\nDu må konfigurere Omnipod før du kan bruke denne funksjonen. Kan ikke kontrollere om bolusdosen ble gitt. Kontroller at Pod\'en gir bolus ved å lytte etter klikkk. Dersom du er sikker på at bolusen ikke var vellykket, bør du manuelt slette bolusoppføring fra Behandlingene, selv om du klikker \'Avbryt bolus\' nå! Klarte ikke å bekrefte om SMB bolus (%1$.2f E) ble gitt. Hvis du er helt sikker på at Bolus ikke ble levert, da bør du manuelt slette SMB-oppføringen fra Behandlinger. En midlertidig basal utføres på Pod, men AAPS har ingen informasjon om denne midlertidige basalen. Vennligst avbryt midlertidig basal manuelt. From 31fb88bbf460869615335c0a05a28dd83775716a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 12 Oct 2023 16:07:17 +0200 Subject: [PATCH 5/5] DB: cleanup TTDs too --- .../src/main/java/app/aaps/database/impl/AppRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt b/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt index c5cb3fbcd4..7cccd799e3 100644 --- a/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt +++ b/database/impl/src/main/java/app/aaps/database/impl/AppRepository.kt @@ -86,7 +86,7 @@ import kotlin.math.roundToInt removed.add(Pair("ExtendedBolus", database.extendedBolusDao.deleteOlderThan(than))) removed.add(Pair("Bolus", database.bolusDao.deleteOlderThan(than))) removed.add(Pair("MultiWaveBolus", database.multiwaveBolusLinkDao.deleteOlderThan(than))) - // keep TDD removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteOlderThan(than))) + removed.add(Pair("TotalDailyDose", database.totalDailyDoseDao.deleteOlderThan(than))) removed.add(Pair("Carbs", database.carbsDao.deleteOlderThan(than))) removed.add(Pair("TemporaryTarget", database.temporaryTargetDao.deleteOlderThan(than))) removed.add(Pair("ApsResultLink", database.apsResultLinkDao.deleteOlderThan(than))) @@ -111,7 +111,7 @@ import kotlin.math.roundToInt removed.add(Pair("CHANGES Bolus", database.bolusDao.deleteTrackedChanges())) removed.add(Pair("CHANGES ExtendedBolus", database.extendedBolusDao.deleteTrackedChanges())) removed.add(Pair("CHANGES MultiWaveBolus", database.multiwaveBolusLinkDao.deleteTrackedChanges())) - // keep TDD removed.add(Pair("CHANGES TotalDailyDose", database.totalDailyDoseDao.deleteTrackedChanges())) + removed.add(Pair("CHANGES TotalDailyDose", database.totalDailyDoseDao.deleteTrackedChanges())) removed.add(Pair("CHANGES Carbs", database.carbsDao.deleteTrackedChanges())) removed.add(Pair("CHANGES TemporaryTarget", database.temporaryTargetDao.deleteTrackedChanges())) removed.add(Pair("CHANGES ApsResultLink", database.apsResultLinkDao.deleteTrackedChanges()))