allow slower NS upload

This commit is contained in:
Milos Kozak 2021-11-04 17:08:15 +01:00
parent ebeac72e74
commit ae399f0bf5
3 changed files with 14 additions and 1 deletions

View file

@ -1,10 +1,12 @@
package info.nightscout.androidaps.plugins.general.nsclient package info.nightscout.androidaps.plugins.general.nsclient
import android.content.Context import android.content.Context
import android.os.SystemClock
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.DeviceStatus import info.nightscout.androidaps.database.entities.DeviceStatus
import info.nightscout.androidaps.database.transactions.* import info.nightscout.androidaps.database.transactions.*
@ -17,6 +19,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAddAck
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog
import info.nightscout.androidaps.receivers.DataWorker import info.nightscout.androidaps.receivers.DataWorker
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
class NSClientAddAckWorker( class NSClientAddAckWorker(
@ -30,6 +33,7 @@ class NSClientAddAckWorker(
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var dataSyncSelector: DataSyncSelector
@Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var sp: SP
override fun doWork(): Result { override fun doWork(): Result {
var ret = Result.success() var ret = Result.success()
@ -37,6 +41,8 @@ class NSClientAddAckWorker(
val ack = dataWorker.pickupObject(inputData.getLong(DataWorker.STORE_KEY, -1)) as NSAddAck? val ack = dataWorker.pickupObject(inputData.getLong(DataWorker.STORE_KEY, -1)) as NSAddAck?
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
if (sp.getBoolean(R.string.key_ns_sync_slow, false)) SystemClock.sleep(1000)
when (ack.originalObject) { when (ack.originalObject) {
is PairTemporaryTarget -> { is PairTemporaryTarget -> {
val pair = ack.originalObject val pair = ack.originalObject

View file

@ -54,6 +54,7 @@
<string name="key_ns_offline_event_last_synced_id" translatable="false">ns_offline_event_last_synced_id</string> <string name="key_ns_offline_event_last_synced_id" translatable="false">ns_offline_event_last_synced_id</string>
<string name="key_ns_profile_store_last_synced_timestamp" translatable="false">ns_profile_store_last_synced_timestamp</string> <string name="key_ns_profile_store_last_synced_timestamp" translatable="false">ns_profile_store_last_synced_timestamp</string>
<string name="key_local_profile_last_change" translatable="false">local_profile_last_change</string> <string name="key_local_profile_last_change" translatable="false">local_profile_last_change</string>
<string name="key_ns_sync_slow" translatable="false">ns_sync_slow</string>
<string name="treatmentssafety_title">Treatments safety</string> <string name="treatmentssafety_title">Treatments safety</string>
<string name="treatmentssafety_maxbolus_title">Max allowed bolus [U]</string> <string name="treatmentssafety_maxbolus_title">Max allowed bolus [U]</string>
@ -1128,5 +1129,6 @@
<string name="invalid_profile_not_accepted">Invalid profile %1$s not accepted from NS</string> <string name="invalid_profile_not_accepted">Invalid profile %1$s not accepted from NS</string>
<string name="view">View</string> <string name="view">View</string>
<string name="errors">Errors</string> <string name="errors">Errors</string>
<string name="ns_sync_slow">Slow down uploads</string>
</resources> </resources>

View file

@ -156,7 +156,7 @@
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_nsclient_advanced" android:key="nsclient_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advancedsettings_title">
<SwitchPreference <SwitchPreference
@ -189,6 +189,11 @@
android:key="@string/key_ns_sync_use_absolute" android:key="@string/key_ns_sync_use_absolute"
android:title="@string/ns_sync_use_absolute_title" /> android:title="@string/ns_sync_use_absolute_title" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_ns_sync_slow"
android:title="@string/ns_sync_slow" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>