better null checks
This commit is contained in:
parent
6d2e159edb
commit
beb4e004bf
8 changed files with 103 additions and 74 deletions
|
@ -5,6 +5,7 @@ import android.text.Spanned
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.db.BgReading
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange
|
import info.nightscout.androidaps.events.EventNetworkChange
|
||||||
import info.nightscout.androidaps.events.EventNewBG
|
import info.nightscout.androidaps.events.EventNewBG
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
|
@ -30,7 +31,6 @@ import io.reactivex.schedulers.Schedulers
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
object TidepoolPlugin : PluginBase(PluginDescription()
|
object TidepoolPlugin : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
.pluginName(R.string.tidepool)
|
.pluginName(R.string.tidepool)
|
||||||
|
@ -39,6 +39,7 @@ object TidepoolPlugin : PluginBase(PluginDescription()
|
||||||
.preferencesId(R.xml.pref_tidepool)
|
.preferencesId(R.xml.pref_tidepool)
|
||||||
.description(R.string.description_tidepool)
|
.description(R.string.description_tidepool)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(L.TIDEPOOL)
|
private val log = LoggerFactory.getLogger(L.TIDEPOOL)
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -75,15 +76,17 @@ object TidepoolPlugin : PluginBase(PluginDescription()
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
.toObservable(EventNewBG::class.java)
|
.toObservable(EventNewBG::class.java)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe({ event ->
|
.filter { it.bgReading != null } // better would be optional in API level >24
|
||||||
if (event.bgReading!!.date < TidepoolUploader.getLastEnd())
|
.map { it.bgReading }
|
||||||
TidepoolUploader.setLastEnd(event.bgReading.date)
|
.subscribe { bgReading ->
|
||||||
|
if (bgReading!!.date < TidepoolUploader.getLastEnd())
|
||||||
|
TidepoolUploader.setLastEnd(bgReading.date)
|
||||||
if (isEnabled(PluginType.GENERAL)
|
if (isEnabled(PluginType.GENERAL)
|
||||||
&& (!SP.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
|
&& (!SP.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
|
||||||
&& (!SP.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
|
&& (!SP.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
|
||||||
&& RateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
|
&& RateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
|
||||||
doUpload()
|
doUpload()
|
||||||
}, {})
|
}
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
.toObservable(EventPreferenceChange::class.java)
|
.toObservable(EventPreferenceChange::class.java)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
|
|
@ -19,14 +19,14 @@ class InfoInterceptor(tag: String) : Interceptor {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
if (request?.body() != null) {
|
request?.body()?.let {
|
||||||
if (L.isEnabled(L.TIDEPOOL)) {
|
if (L.isEnabled(L.TIDEPOOL)) {
|
||||||
log.debug("Interceptor Body size: " + request.body()!!.contentLength())
|
log.debug("Interceptor Body size: " + it.contentLength())
|
||||||
val requestBuffer = Buffer()
|
val requestBuffer = Buffer()
|
||||||
request.body()!!.writeTo(requestBuffer)
|
it.writeTo(requestBuffer)
|
||||||
log.debug("Interceptor Body: " + requestBuffer.readUtf8())
|
log.debug("Interceptor Body: " + requestBuffer.readUtf8())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chain.proceed(request!!)
|
return chain.proceed(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.messages.AuthReplyMes
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.messages.DatasetReplyMessage
|
import info.nightscout.androidaps.plugins.general.tidepool.messages.DatasetReplyMessage
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
|
||||||
class Session (var authHeader: String?, private var sessionTokenHeader: String) {
|
class Session(var authHeader: String?, private var sessionTokenHeader: String) {
|
||||||
|
|
||||||
val service = TidepoolUploader.getRetrofitInstance()?.create(TidepoolApiService::class.java)
|
val service = TidepoolUploader.getRetrofitInstance()?.create(TidepoolApiService::class.java)
|
||||||
|
|
||||||
|
@ -28,9 +28,12 @@ class Session (var authHeader: String?, private var sessionTokenHeader: String)
|
||||||
if (obj is AuthReplyMessage) {
|
if (obj is AuthReplyMessage) {
|
||||||
authReply = obj
|
authReply = obj
|
||||||
} else if (obj is List<*>) {
|
} else if (obj is List<*>) {
|
||||||
val list = obj as List<*>?
|
val list = obj as? List<*>?
|
||||||
if (list!!.isNotEmpty() && list[0] is DatasetReplyMessage) {
|
|
||||||
datasetReply = list[0] as DatasetReplyMessage
|
list?.getOrNull(0)?.let {
|
||||||
|
if (it is DatasetReplyMessage) {
|
||||||
|
datasetReply = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (obj is DatasetReplyMessage) {
|
} else if (obj is DatasetReplyMessage) {
|
||||||
datasetReply = obj
|
datasetReply = obj
|
||||||
|
|
|
@ -6,8 +6,8 @@ import android.os.SystemClock
|
||||||
import info.nightscout.androidaps.BuildConfig
|
import info.nightscout.androidaps.BuildConfig
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.messages.*
|
import info.nightscout.androidaps.plugins.general.tidepool.messages.*
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
@ -28,7 +28,6 @@ object TidepoolUploader {
|
||||||
|
|
||||||
private var wl: PowerManager.WakeLock? = null
|
private var wl: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
|
|
||||||
private const val INTEGRATION_BASE_URL = "https://int-api.tidepool.org"
|
private const val INTEGRATION_BASE_URL = "https://int-api.tidepool.org"
|
||||||
private const val PRODUCTION_BASE_URL = "https://api.tidepool.org"
|
private const val PRODUCTION_BASE_URL = "https://api.tidepool.org"
|
||||||
|
|
||||||
|
@ -82,10 +81,11 @@ object TidepoolUploader {
|
||||||
// TODO failure backoff
|
// TODO failure backoff
|
||||||
extendWakeLock(30000)
|
extendWakeLock(30000)
|
||||||
session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
|
session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
|
||||||
if (session?.authHeader != null) {
|
val authHeader = session?.authHeader
|
||||||
|
if (authHeader != null) {
|
||||||
connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTING
|
connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTING
|
||||||
RxBus.send(EventTidepoolStatus(("Connecting")))
|
RxBus.send(EventTidepoolStatus(("Connecting")))
|
||||||
val call = session!!.service?.getLogin(session?.authHeader!!)
|
val call = session?.service?.getLogin(authHeader)
|
||||||
|
|
||||||
call?.enqueue(TidepoolCallback<AuthReplyMessage>(session!!, "Login", {
|
call?.enqueue(TidepoolCallback<AuthReplyMessage>(session!!, "Login", {
|
||||||
startSession(session!!, doUpload)
|
startSession(session!!, doUpload)
|
||||||
|
@ -105,22 +105,20 @@ object TidepoolUploader {
|
||||||
|
|
||||||
fun testLogin(rootContext: Context) {
|
fun testLogin(rootContext: Context) {
|
||||||
val session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
|
val session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
|
||||||
if (session.authHeader != null) {
|
session.authHeader?.let {
|
||||||
val call = session.service!!.getLogin(session.authHeader!!)
|
val call = session.service?.getLogin(it)
|
||||||
|
|
||||||
call.enqueue(TidepoolCallback<AuthReplyMessage>(session, "Login", {
|
call?.enqueue(TidepoolCallback<AuthReplyMessage>(session, "Login", {
|
||||||
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Successfully logged into Tidepool.", null)
|
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Successfully logged into Tidepool.", null)
|
||||||
}, {
|
}, {
|
||||||
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.", null)
|
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.", null)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
} else {
|
|
||||||
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly", null)
|
|
||||||
}
|
}
|
||||||
|
?: OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly", null)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun loginFailed() {
|
private fun loginFailed() {
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
}
|
}
|
||||||
|
@ -173,32 +171,35 @@ object TidepoolUploader {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun doUpload() {
|
fun doUpload() {
|
||||||
|
session.let { session ->
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
log.error("Session is null, cannot proceed")
|
log.error("Session is null, cannot proceed")
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
extendWakeLock(60000)
|
extendWakeLock(60000)
|
||||||
session!!.iterations++
|
session.iterations++
|
||||||
val chunk = UploadChunk.getNext(session)
|
val chunk = UploadChunk.getNext(session)
|
||||||
when {
|
when {
|
||||||
chunk == null -> {
|
chunk == null -> {
|
||||||
log.error("Upload chunk is null, cannot proceed")
|
log.error("Upload chunk is null, cannot proceed")
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk.length == 2 -> {
|
chunk.length == 2 -> {
|
||||||
if (L.isEnabled(L.TIDEPOOL)) log.debug("Empty dataset - marking as succeeded")
|
if (L.isEnabled(L.TIDEPOOL)) log.debug("Empty dataset - marking as succeeded")
|
||||||
RxBus.send(EventTidepoolStatus(("No data to upload")))
|
RxBus.send(EventTidepoolStatus(("No data to upload")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
unploadNext()
|
unploadNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val body = RequestBody.create(MediaType.parse("application/json"), chunk)
|
val body = RequestBody.create(MediaType.parse("application/json"), chunk)
|
||||||
|
|
||||||
RxBus.send(EventTidepoolStatus(("Uploading")))
|
RxBus.send(EventTidepoolStatus(("Uploading")))
|
||||||
val call = session!!.service!!.doUpload(session!!.token!!, session!!.datasetReply!!.getUploadId()!!, body)
|
val call = session.service!!.doUpload(session.token!!, session.datasetReply!!.getUploadId()!!, body)
|
||||||
call.enqueue(TidepoolCallback<UploadReplyMessage>(session!!, "Data Upload", {
|
call.enqueue(TidepoolCallback<UploadReplyMessage>(session, "Data Upload", {
|
||||||
setLastEnd(session!!.end)
|
setLastEnd(session.end)
|
||||||
RxBus.send(EventTidepoolStatus(("Upload completed OK")))
|
RxBus.send(EventTidepoolStatus(("Upload completed OK")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
unploadNext()
|
unploadNext()
|
||||||
|
@ -209,6 +210,7 @@ object TidepoolUploader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun unploadNext() {
|
private fun unploadNext() {
|
||||||
if (getLastEnd() < DateUtil.now() - T.mins(1).msecs()) {
|
if (getLastEnd() < DateUtil.now() - T.mins(1).msecs()) {
|
||||||
|
@ -238,10 +240,16 @@ object TidepoolUploader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAllData() {
|
fun deleteAllData() {
|
||||||
if (session!!.authReply!!.userid != null) {
|
val session = this.session
|
||||||
|
val token = session?.token
|
||||||
|
val userid = session?.authReply?.userid
|
||||||
|
try {
|
||||||
|
requireNotNull(session)
|
||||||
|
requireNotNull(token)
|
||||||
|
requireNotNull(userid)
|
||||||
extendWakeLock(60000)
|
extendWakeLock(60000)
|
||||||
val call = session!!.service?.deleteAllData(session!!.token!!, session!!.authReply!!.userid!!)
|
val call = session.service?.deleteAllData(token, userid)
|
||||||
call?.enqueue(TidepoolCallback(session!!, "Delete all data", {
|
call?.enqueue(TidepoolCallback(session, "Delete all data", {
|
||||||
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
|
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
|
||||||
RxBus.send(EventTidepoolStatus(("All data removed OK")))
|
RxBus.send(EventTidepoolStatus(("All data removed OK")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
|
@ -250,7 +258,7 @@ object TidepoolUploader {
|
||||||
RxBus.send(EventTidepoolStatus(("All data remove FAILED")))
|
RxBus.send(EventTidepoolStatus(("All data remove FAILED")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
}))
|
}))
|
||||||
} else {
|
} catch (e: IllegalArgumentException) {
|
||||||
log.error("Got login response but cannot determine userId - cannot proceed")
|
log.error("Got login response but cannot determine userId - cannot proceed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +279,6 @@ object TidepoolUploader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun extendWakeLock(ms: Long) {
|
private fun extendWakeLock(ms: Long) {
|
||||||
if (wl == null) {
|
if (wl == null) {
|
||||||
|
@ -286,14 +293,15 @@ object TidepoolUploader {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun releaseWakeLock() {
|
private fun releaseWakeLock() {
|
||||||
if (wl == null) return
|
wl?.let {
|
||||||
if (wl!!.isHeld) {
|
if (it.isHeld) {
|
||||||
try {
|
try {
|
||||||
wl!!.release()
|
it.release()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Error releasing wakelock: $e")
|
log.error("Error releasing wakelock: $e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -120,8 +120,7 @@ object UploadChunk {
|
||||||
val pss = MainApp.getDbHelper().getProfileSwitchEventsFromTime(start, end, true)
|
val pss = MainApp.getDbHelper().getProfileSwitchEventsFromTime(start, end, true)
|
||||||
val selection = LinkedList<ProfileElement>()
|
val selection = LinkedList<ProfileElement>()
|
||||||
for (ps in pss) {
|
for (ps in pss) {
|
||||||
val pe = ProfileElement(ps)
|
ProfileElement.newInstanceOrNull(ps)?.let { selection.add(it) }
|
||||||
selection.add(pe)
|
|
||||||
}
|
}
|
||||||
if (selection.size > 0)
|
if (selection.size > 0)
|
||||||
RxBus.send(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload"))
|
RxBus.send(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload"))
|
||||||
|
|
|
@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.InstanceId
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ProfileElement(ps: ProfileSwitch)
|
class ProfileElement private constructor(ps: ProfileSwitch)
|
||||||
: BaseElement(ps.date, UUID.nameUUIDFromBytes(("AAPS-profile" + ps.date).toByteArray()).toString()) {
|
: BaseElement(ps.date, UUID.nameUUIDFromBytes(("AAPS-profile" + ps.date).toByteArray()).toString()) {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
|
@ -25,9 +25,11 @@ class ProfileElement(ps: ProfileSwitch)
|
||||||
@Expose
|
@Expose
|
||||||
internal var insulinSensitivities: IsfProfile = IsfProfile()
|
internal var insulinSensitivities: IsfProfile = IsfProfile()
|
||||||
@Expose
|
@Expose
|
||||||
internal var deviceId: String = TidepoolUploader.PUMPTYPE + ":" + (ConfigBuilderPlugin.getPlugin().activePump?.serialNumber() ?: InstanceId.instanceId())
|
internal var deviceId: String = TidepoolUploader.PUMPTYPE + ":" + (ConfigBuilderPlugin.getPlugin().activePump?.serialNumber()
|
||||||
|
?: InstanceId.instanceId())
|
||||||
@Expose
|
@Expose
|
||||||
internal var deviceSerialNumber: String = ConfigBuilderPlugin.getPlugin().activePump?.serialNumber() ?: InstanceId.instanceId()
|
internal var deviceSerialNumber: String = ConfigBuilderPlugin.getPlugin().activePump?.serialNumber()
|
||||||
|
?: InstanceId.instanceId()
|
||||||
@Expose
|
@Expose
|
||||||
internal var clockDriftOffset: Long = 0
|
internal var clockDriftOffset: Long = 0
|
||||||
@Expose
|
@Expose
|
||||||
|
@ -35,7 +37,8 @@ class ProfileElement(ps: ProfileSwitch)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
type = "pumpSettings"
|
type = "pumpSettings"
|
||||||
val profile: Profile = ps.getProfileObject()!!
|
val profile: Profile? = ps.profileObject
|
||||||
|
checkNotNull(profile)
|
||||||
for (br in profile.basalValues)
|
for (br in profile.basalValues)
|
||||||
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
|
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
|
||||||
for (target in profile.singleTargets)
|
for (target in profile.singleTargets)
|
||||||
|
@ -94,4 +97,15 @@ class ProfileElement(ps: ProfileSwitch)
|
||||||
internal var amount: Double
|
internal var amount: Double
|
||||||
)
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun newInstanceOrNull(ps: ProfileSwitch): ProfileElement? = try {
|
||||||
|
ProfileElement(ps)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,13 @@ object RateLimit {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun rateLimit(name: String, seconds: Int): Boolean {
|
fun rateLimit(name: String, seconds: Int): Boolean {
|
||||||
// check if over limit
|
// check if over limit
|
||||||
if (rateLimits.containsKey(name) && DateUtil.now() - rateLimits[name]!! < T.secs(seconds.toLong()).msecs()) {
|
rateLimits[name]?.let {
|
||||||
|
if (DateUtil.now() - it < T.secs(seconds.toLong()).msecs()) {
|
||||||
if (L.isEnabled(L.TIDEPOOL))
|
if (L.isEnabled(L.TIDEPOOL))
|
||||||
log.debug("$name rate limited: $seconds seconds")
|
log.debug("$name rate limited: $seconds seconds")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// not over limit
|
// not over limit
|
||||||
rateLimits[name] = DateUtil.now()
|
rateLimits[name] = DateUtil.now()
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -188,7 +188,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
calculatedTotalInsulin = 0.0
|
calculatedTotalInsulin = 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription!!.bolusStep
|
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.bolusStep ?: 0.1
|
||||||
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
|
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
|
||||||
|
|
||||||
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
||||||
|
@ -318,7 +318,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
detailedBolusInfo.boluscalc = nsJSON()
|
detailedBolusInfo.boluscalc = nsJSON()
|
||||||
detailedBolusInfo.source = Source.USER
|
detailedBolusInfo.source = Source.USER
|
||||||
detailedBolusInfo.notes = notes
|
detailedBolusInfo.notes = notes
|
||||||
if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription!!.storesCarbInfo) {
|
if (detailedBolusInfo.insulin > 0 || ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.storesCarbInfo == true) {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
|
Loading…
Reference in a new issue