use fun instead of val in pump interface
This commit is contained in:
parent
cae9588950
commit
531c74de6a
15 changed files with 119 additions and 116 deletions
|
@ -196,7 +196,7 @@ open class LoopPlugin @Inject constructor(
|
||||||
val apsMode = sp.getString(R.string.key_aps_mode, "open")
|
val apsMode = sp.getString(R.string.key_aps_mode, "open")
|
||||||
val pump = activePlugin.activePump
|
val pump = activePlugin.activePump
|
||||||
var isLGS = false
|
var isLGS = false
|
||||||
if (!isSuspended && !pump.isSuspended) if (closedLoopEnabled.value()) if (maxIobAllowed == hardLimits.MAXIOB_LGS || apsMode == "lgs") isLGS = true
|
if (!isSuspended && !pump.isSuspended()) if (closedLoopEnabled.value()) if (maxIobAllowed == hardLimits.MAXIOB_LGS || apsMode == "lgs") isLGS = true
|
||||||
return isLGS
|
return isLGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ open class LoopPlugin @Inject constructor(
|
||||||
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.loopsuspended)))
|
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.loopsuspended)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pump.isSuspended) {
|
if (pump.isSuspended()) {
|
||||||
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.pumpsuspended))
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.pumpsuspended))
|
||||||
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.pumpsuspended)))
|
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.pumpsuspended)))
|
||||||
return
|
return
|
||||||
|
@ -511,12 +511,12 @@ open class LoopPlugin @Inject constructor(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val pump = activePlugin.activePump
|
val pump = activePlugin.activePump
|
||||||
if (!pump.isInitialized) {
|
if (!pump.isInitialized()) {
|
||||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
||||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pump.isSuspended) {
|
if (pump.isSuspended()) {
|
||||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
||||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
||||||
return
|
return
|
||||||
|
@ -578,12 +578,12 @@ open class LoopPlugin @Inject constructor(
|
||||||
.enacted(false).success(false))?.run()
|
.enacted(false).success(false))?.run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!pump.isInitialized) {
|
if (!pump.isInitialized()) {
|
||||||
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
||||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (pump.isSuspended) {
|
if (pump.isSuspended()) {
|
||||||
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
||||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
||||||
return
|
return
|
||||||
|
|
|
@ -256,10 +256,10 @@ class ActionsFragment : DaggerFragment() {
|
||||||
profileSwitch?.visibility = (
|
profileSwitch?.visibility = (
|
||||||
activePlugin.activeProfileInterface.profile != null &&
|
activePlugin.activeProfileInterface.profile != null &&
|
||||||
pump.pumpDescription.isSetBasalProfileCapable &&
|
pump.pumpDescription.isSetBasalProfileCapable &&
|
||||||
pump.isInitialized &&
|
pump.isInitialized() &&
|
||||||
!pump.isSuspended).toVisibility()
|
!pump.isSuspended()).toVisibility()
|
||||||
|
|
||||||
if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) {
|
if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses) {
|
||||||
extendedBolus?.visibility = View.GONE
|
extendedBolus?.visibility = View.GONE
|
||||||
extendedBolusCancel?.visibility = View.GONE
|
extendedBolusCancel?.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
@ -275,7 +275,7 @@ class ActionsFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized || pump.isSuspended) {
|
if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) {
|
||||||
setTempBasal?.visibility = View.GONE
|
setTempBasal?.visibility = View.GONE
|
||||||
cancelTempBasal?.visibility = View.GONE
|
cancelTempBasal?.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
@ -292,7 +292,7 @@ class ActionsFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
val activeBgSource = activePlugin.activeBgSource
|
val activeBgSource = activePlugin.activeBgSource
|
||||||
historyBrowser?.visibility = (profile != null).toVisibility()
|
historyBrowser?.visibility = (profile != null).toVisibility()
|
||||||
fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility()
|
fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized() && !pump.isSuspended()).toVisibility()
|
||||||
pumpBatteryChange?.visibility = (pump.pumpDescription.isBatteryReplaceable || (pump is OmnipodErosPumpPlugin && pump.isUseRileyLinkBatteryLevel && pump.isBatteryChangeLoggingEnabled)).toVisibility()
|
pumpBatteryChange?.visibility = (pump.pumpDescription.isBatteryReplaceable || (pump is OmnipodErosPumpPlugin && pump.isUseRileyLinkBatteryLevel && pump.isBatteryChangeLoggingEnabled)).toVisibility()
|
||||||
tempTarget?.visibility = (profile != null && config.APS).toVisibility()
|
tempTarget?.visibility = (profile != null && config.APS).toVisibility()
|
||||||
tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility()
|
tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility()
|
||||||
|
|
|
@ -446,7 +446,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
|
|
||||||
// QuickWizard button
|
// QuickWizard button
|
||||||
val quickWizardEntry = quickWizard.getActive()
|
val quickWizardEntry = quickWizard.getActive()
|
||||||
if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized && !pump.isSuspended) {
|
if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized() && !pump.isSuspended()) {
|
||||||
binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE
|
binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE
|
||||||
val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false)
|
val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false)
|
||||||
binding.buttonsLayout.quickWizardButton.text = quickWizardEntry.buttonText() + "\n" + resourceHelper.gs(R.string.format_carbs, quickWizardEntry.carbs()) +
|
binding.buttonsLayout.quickWizardButton.text = quickWizardEntry.buttonText() + "\n" + resourceHelper.gs(R.string.format_carbs, quickWizardEntry.carbs()) +
|
||||||
|
@ -463,7 +463,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
(lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result
|
(lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result
|
||||||
lastRun.constraintsProcessed?.isChangeRequested == true // change is requested
|
lastRun.constraintsProcessed?.isChangeRequested == true // change is requested
|
||||||
|
|
||||||
if (showAcceptButton && pump.isInitialized && !pump.isSuspended && loopPlugin.isEnabled(PluginType.LOOP)) {
|
if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE
|
binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE
|
||||||
binding.buttonsLayout.acceptTempButton.text = "${resourceHelper.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}"
|
binding.buttonsLayout.acceptTempButton.text = "${resourceHelper.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}"
|
||||||
} else {
|
} else {
|
||||||
|
@ -471,10 +471,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
}
|
}
|
||||||
|
|
||||||
// **** Various treatment buttons ****
|
// **** Various treatment buttons ****
|
||||||
binding.buttonsLayout.carbsButton.visibility = ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized && !pump.isSuspended) && profile != null && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility()
|
binding.buttonsLayout.carbsButton.visibility = ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) && profile != null && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility()
|
||||||
binding.buttonsLayout.treatmentButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility()
|
binding.buttonsLayout.treatmentButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility()
|
||||||
binding.buttonsLayout.wizardButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility()
|
binding.buttonsLayout.wizardButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility()
|
||||||
binding.buttonsLayout.insulinButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility()
|
binding.buttonsLayout.insulinButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility()
|
||||||
|
|
||||||
// **** Calibration & CGM buttons ****
|
// **** Calibration & CGM buttons ****
|
||||||
val xDripIsBgSource = xdripPlugin.isEnabled(PluginType.BGSOURCE)
|
val xDripIsBgSource = xdripPlugin.isEnabled(PluginType.BGSOURCE)
|
||||||
|
@ -633,7 +633,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
binding.infoLayout.apsModeText.visibility = View.VISIBLE
|
binding.infoLayout.apsModeText.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
pump.isSuspended -> {
|
pump.isSuspended() -> {
|
||||||
binding.infoLayout.apsMode.setImageResource(if (pump.pumpDescription.pumpType == PumpType.Insulet_Omnipod) {
|
binding.infoLayout.apsMode.setImageResource(if (pump.pumpDescription.pumpType == PumpType.Insulet_Omnipod) {
|
||||||
// For Omnipod, indicate the pump as disconnected when it's suspended.
|
// For Omnipod, indicate the pump as disconnected when it's suspended.
|
||||||
// The only way to 'reconnect' it, is through the Omnipod tab
|
// The only way to 'reconnect' it, is through the Omnipod tab
|
||||||
|
@ -898,8 +898,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal] -> useBGIForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal] -> useBGIForScale = true
|
||||||
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true
|
||||||
}
|
}
|
||||||
var alignIobScale = menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]
|
val alignIobScale = menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]
|
||||||
var alignDevBgiScale = menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal]
|
val alignDevBgiScale = menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal]
|
||||||
|
|
||||||
if (menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, now, useABSForScale, 1.0)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, now, useABSForScale, 1.0)
|
||||||
if (menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, now, useIobForScale, 1.0, menuChartSettings[g + 1][OverviewMenus.CharType.PRE.ordinal], alignIobScale)
|
if (menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, now, useIobForScale, 1.0, menuChartSettings[g + 1][OverviewMenus.CharType.PRE.ordinal], alignIobScale)
|
||||||
|
|
|
@ -38,12 +38,12 @@ 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.receivers.DataReceiver
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.*
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
|
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import java.text.Normalizer
|
import java.text.Normalizer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -270,7 +270,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
"BOLUS" ->
|
"BOLUS" ->
|
||||||
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
|
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
|
||||||
else if (divided.size == 2 && DateUtil.now() - lastRemoteBolusTime < minDistance) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotebolusnotallowed)))
|
else if (divided.size == 2 && DateUtil.now() - lastRemoteBolusTime < minDistance) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotebolusnotallowed)))
|
||||||
else if (divided.size == 2 && pump.isSuspended) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.pumpsuspended)))
|
else if (divided.size == 2 && pump.isSuspended()) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.pumpsuspended)))
|
||||||
else if (divided.size == 2 || divided.size == 3) processBOLUS(divided, receivedSms)
|
else if (divided.size == 2 || divided.size == 3) processBOLUS(divided, receivedSms)
|
||||||
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||||
"CARBS" ->
|
"CARBS" ->
|
||||||
|
|
|
@ -50,7 +50,7 @@ import javax.inject.Singleton
|
||||||
class ActionStringHandler @Inject constructor(
|
class ActionStringHandler @Inject constructor(
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val rxBus: RxBusWrapper,
|
private val rxBus: RxBusWrapper,
|
||||||
private val aapsSchedulers: AapsSchedulers,
|
aapsSchedulers: AapsSchedulers,
|
||||||
private val resourceHelper: ResourceHelper,
|
private val resourceHelper: ResourceHelper,
|
||||||
private val injector: HasAndroidInjector,
|
private val injector: HasAndroidInjector,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
@ -262,7 +262,7 @@ class ActionStringHandler @Inject constructor(
|
||||||
rAction = "statusmessage"
|
rAction = "statusmessage"
|
||||||
rMessage = "OLD DATA - "
|
rMessage = "OLD DATA - "
|
||||||
//if pump is not busy: try to fetch data
|
//if pump is not busy: try to fetch data
|
||||||
if (activePump.isBusy) {
|
if (activePump.isBusy()) {
|
||||||
rMessage += resourceHelper.gs(R.string.pumpbusy)
|
rMessage += resourceHelper.gs(R.string.pumpbusy)
|
||||||
} else {
|
} else {
|
||||||
rMessage += "trying to fetch data from pump."
|
rMessage += "trying to fetch data from pump."
|
||||||
|
|
|
@ -49,12 +49,12 @@ class MDIPlugin @Inject constructor(
|
||||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||||
|
|
||||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector)
|
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector)
|
||||||
override val isInitialized: Boolean = true
|
override fun isInitialized(): Boolean = true
|
||||||
override val isSuspended: Boolean = false
|
override fun isSuspended(): Boolean = false
|
||||||
override val isBusy: Boolean = false
|
override fun isBusy(): Boolean = false
|
||||||
override val isConnected: Boolean = true
|
override fun isConnected(): Boolean = true
|
||||||
override val isConnecting: Boolean = false
|
override fun isConnecting(): Boolean = false
|
||||||
override val isHandshakeInProgress: Boolean = false
|
override fun isHandshakeInProgress(): Boolean = false
|
||||||
override fun connect(reason: String) {}
|
override fun connect(reason: String) {}
|
||||||
override fun disconnect(reason: String) {}
|
override fun disconnect(reason: String) {}
|
||||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||||
|
@ -140,6 +140,6 @@ class MDIPlugin @Inject constructor(
|
||||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AndroidAPS
|
override fun manufacturer(): ManufacturerType = ManufacturerType.AndroidAPS
|
||||||
override fun model(): PumpType = PumpType.MDI
|
override fun model(): PumpType = PumpType.MDI
|
||||||
override fun serialNumber(): String = instanceId()
|
override fun serialNumber(): String = instanceId()
|
||||||
override fun shortStatus(veryShort: Boolean): String =model().model
|
override fun shortStatus(veryShort: Boolean): String = model().model
|
||||||
override fun canHandleDST(): Boolean = true
|
override fun canHandleDST(): Boolean = true
|
||||||
}
|
}
|
|
@ -133,12 +133,12 @@ class VirtualPumpPlugin @Inject constructor(
|
||||||
return PumpEnactResult(injector)
|
return PumpEnactResult(injector)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val isInitialized: Boolean = true
|
override fun isInitialized(): Boolean = true
|
||||||
override val isSuspended: Boolean = false
|
override fun isSuspended(): Boolean = false
|
||||||
override val isBusy: Boolean = false
|
override fun isBusy(): Boolean = false
|
||||||
override val isConnected: Boolean = true
|
override fun isConnected(): Boolean = true
|
||||||
override val isConnecting: Boolean = false
|
override fun isConnecting(): Boolean = false
|
||||||
override val isHandshakeInProgress: Boolean = false
|
override fun isHandshakeInProgress(): Boolean = false
|
||||||
|
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
//if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
|
//if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
|
||||||
|
|
|
@ -31,7 +31,6 @@ class QueueThread internal constructor(
|
||||||
var waitingForDisconnect = false
|
var waitingForDisconnect = false
|
||||||
private var mWakeLock: PowerManager.WakeLock? = null
|
private var mWakeLock: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mWakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, resourceHelper.gs(R.string.app_name) + ":QueueThread")
|
mWakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, resourceHelper.gs(R.string.app_name) + ":QueueThread")
|
||||||
}
|
}
|
||||||
|
@ -46,7 +45,7 @@ class QueueThread internal constructor(
|
||||||
while (true) {
|
while (true) {
|
||||||
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
|
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
|
||||||
val pump = activePlugin.activePump
|
val pump = activePlugin.activePump
|
||||||
if (!pump.isConnected && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
||||||
rxBus.send(EventDismissBolusProgressIfRunning(null))
|
rxBus.send(EventDismissBolusProgressIfRunning(null))
|
||||||
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout)))
|
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout)))
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "timed out")
|
aapsLogger.debug(LTag.PUMPQUEUE, "timed out")
|
||||||
|
@ -86,19 +85,19 @@ class QueueThread internal constructor(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pump.isHandshakeInProgress) {
|
if (pump.isHandshakeInProgress()) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "handshaking $secondsElapsed")
|
aapsLogger.debug(LTag.PUMPQUEUE, "handshaking $secondsElapsed")
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, secondsElapsed.toInt()))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, secondsElapsed.toInt()))
|
||||||
SystemClock.sleep(100)
|
SystemClock.sleep(100)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (pump.isConnecting) {
|
if (pump.isConnecting()) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "connecting $secondsElapsed")
|
aapsLogger.debug(LTag.PUMPQUEUE, "connecting $secondsElapsed")
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
||||||
SystemClock.sleep(1000)
|
SystemClock.sleep(1000)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (!pump.isConnected) {
|
if (!pump.isConnected()) {
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "connect")
|
aapsLogger.debug(LTag.PUMPQUEUE, "connect")
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
||||||
pump.connect("Connection needed")
|
pump.connect("Connection needed")
|
||||||
|
|
|
@ -29,6 +29,7 @@ import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||||
|
@ -44,6 +45,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val KEEP_ALIVE_MILLISECONDS = T.mins(5).msecs()
|
private val KEEP_ALIVE_MILLISECONDS = T.mins(5).msecs()
|
||||||
private val STATUS_UPDATE_FREQUENCY = T.mins(15).msecs()
|
private val STATUS_UPDATE_FREQUENCY = T.mins(15).msecs()
|
||||||
private val IOB_UPDATE_FREQUENCY_IN_MINS = 5L
|
private val IOB_UPDATE_FREQUENCY_IN_MINS = 5L
|
||||||
|
@ -128,10 +130,10 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
}
|
}
|
||||||
if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) {
|
if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) {
|
||||||
rxBus.send(EventProfileNeedsUpdate())
|
rxBus.send(EventProfileNeedsUpdate())
|
||||||
} else if (isStatusOutdated && !pump.isBusy) {
|
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||||
lastReadStatus = System.currentTimeMillis()
|
lastReadStatus = System.currentTimeMillis()
|
||||||
commandQueue.readStatus("KeepAlive. Status outdated.", null)
|
commandQueue.readStatus("KeepAlive. Status outdated.", null)
|
||||||
} else if (isBasalOutdated && !pump.isBusy) {
|
} else if (isBasalOutdated && !pump.isBusy()) {
|
||||||
lastReadStatus = System.currentTimeMillis()
|
lastReadStatus = System.currentTimeMillis()
|
||||||
commandQueue.readStatus("KeepAlive. Basal outdated.", null)
|
commandQueue.readStatus("KeepAlive. Basal outdated.", null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,9 +217,11 @@ class SWDefinition @Inject constructor(
|
||||||
.updateDelay(5)
|
.updateDelay(5)
|
||||||
.label(R.string.treatmentssafety_maxcarbs_title)
|
.label(R.string.treatmentssafety_maxcarbs_title)
|
||||||
.comment(R.string.common_values))
|
.comment(R.string.common_values))
|
||||||
.validator { sp.contains(R.string.key_age)
|
.validator {
|
||||||
|
sp.contains(R.string.key_age)
|
||||||
&& sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0
|
&& sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0
|
||||||
&& sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0 }
|
&& sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0
|
||||||
|
}
|
||||||
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(SWPlugin(injector, this)
|
.add(SWPlugin(injector, this)
|
||||||
|
@ -303,7 +305,7 @@ class SWDefinition @Inject constructor(
|
||||||
|
|
||||||
// For Omnipod, consider the pump initialized when a RL has been configured successfully
|
// For Omnipod, consider the pump initialized when a RL has been configured successfully
|
||||||
// Users will be prompted to activate a Pod after completing the setup wizard.
|
// Users will be prompted to activate a Pod after completing the setup wizard.
|
||||||
return activePump.isInitialized || (activePump is OmnipodErosPumpPlugin && activePump.isRileyLinkReady)
|
return activePump.isInitialized() || (activePump is OmnipodErosPumpPlugin && activePump.isRileyLinkReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val screenAps = SWScreen(injector, R.string.configbuilder_aps)
|
private val screenAps = SWScreen(injector, R.string.configbuilder_aps)
|
||||||
|
|
|
@ -14,27 +14,29 @@ import org.json.JSONObject
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface {
|
class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface {
|
||||||
|
|
||||||
override var isConnected = false
|
var connected = false
|
||||||
override var isConnecting = false
|
|
||||||
override var isHandshakeInProgress = false
|
override fun isConnected() = connected
|
||||||
|
override fun isConnecting() = false
|
||||||
|
override fun isHandshakeInProgress() = false
|
||||||
val lastData = 0L
|
val lastData = 0L
|
||||||
|
|
||||||
val baseBasal = 0.0
|
val baseBasal = 0.0
|
||||||
override val pumpDescription = PumpDescription()
|
override val pumpDescription = PumpDescription()
|
||||||
|
|
||||||
override val isInitialized: Boolean = true
|
override fun isInitialized(): Boolean = true
|
||||||
override val isSuspended: Boolean = false
|
override fun isSuspended(): Boolean = false
|
||||||
override val isBusy: Boolean = false
|
override fun isBusy(): Boolean = false
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
isConnected = true
|
connected = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun disconnect(reason: String) {
|
override fun disconnect(reason: String) {
|
||||||
isConnected = false
|
connected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopConnecting() {
|
override fun stopConnecting() {
|
||||||
isConnected = false
|
connected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
@file:Suppress("SpellCheckingInspection")
|
||||||
|
|
||||||
package info.nightscout.androidaps.plugins.general.smsCommunicator
|
package info.nightscout.androidaps.plugins.general.smsCommunicator
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
@ -155,9 +157,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||||
|
|
||||||
`when`(virtualPumpPlugin.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump")
|
`when`(virtualPumpPlugin.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump")
|
||||||
`when`(virtualPumpPlugin.isSuspended).thenReturn(false)
|
`when`(virtualPumpPlugin.isSuspended()).thenReturn(false)
|
||||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription())
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription())
|
||||||
`when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS);
|
`when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS)
|
||||||
|
|
||||||
`when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0))
|
`when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0))
|
||||||
`when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0))
|
`when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0))
|
||||||
|
@ -187,7 +189,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopisdisabled)).thenReturn("Loop is disabled")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loopisdisabled)).thenReturn("Loop is disabled")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopisenabled)).thenReturn("Loop is enabled")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loopisenabled)).thenReturn("Loop is enabled")
|
||||||
`when`(resourceHelper.gs(R.string.wrongformat)).thenReturn("Wrong format")
|
`when`(resourceHelper.gs(R.string.wrongformat)).thenReturn("Wrong format")
|
||||||
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.wrongTbrDuration), ArgumentMatchers.any())).thenAnswer({ i: InvocationOnMock -> "TBR duration must be a multiple of " + i.getArguments()[1] + " minutes and greater than 0." })
|
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.wrongTbrDuration), ArgumentMatchers.any())).thenAnswer { i: InvocationOnMock -> "TBR duration must be a multiple of " + i.arguments[1] + " minutes and greater than 0." }
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loophasbeendisabled)).thenReturn("Loop has been disabled")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loophasbeendisabled)).thenReturn("Loop has been disabled")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)).thenReturn("Loop has been enabled")
|
`when`(resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)).thenReturn("Loop has been enabled")
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)).thenReturn("Temp basal canceled")
|
`when`(resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)).thenReturn("Temp basal canceled")
|
||||||
|
@ -241,8 +243,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun processSettingsTest() {
|
fun processSettingsTest() {
|
||||||
// called from constructor
|
// called from constructor
|
||||||
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers.get(0))
|
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers[0])
|
||||||
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers.get(1))
|
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers[1])
|
||||||
Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size)
|
Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,17 +261,16 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.messageToConfirm = null
|
smsCommunicatorPlugin.messageToConfirm = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun _isAllowedNumberTest() {
|
@Test fun isAllowedNumberTest() {
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.isAllowedNumber("5678"))
|
Assert.assertTrue(smsCommunicatorPlugin.isAllowedNumber("5678"))
|
||||||
Assert.assertFalse(smsCommunicatorPlugin.isAllowedNumber("56"))
|
Assert.assertFalse(smsCommunicatorPlugin.isAllowedNumber("56"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processSmsTest() {
|
@Test fun processSmsTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
// SMS from not allowed number should be ignored
|
// SMS from not allowed number should be ignored
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("12", "aText")
|
var sms = Sms("12", "aText")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertTrue(sms.ignored)
|
Assert.assertTrue(sms.ignored)
|
||||||
Assert.assertEquals("aText", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("aText", smsCommunicatorPlugin.messages[0].text)
|
||||||
|
@ -348,7 +349,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
//LOOP DISABLE : from enabled
|
//LOOP DISABLE : from enabled
|
||||||
hasBeenRun = false
|
hasBeenRun = false
|
||||||
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
||||||
PowerMockito.doAnswer(Answer { _: InvocationOnMock? ->
|
PowerMockito.doAnswer(Answer {
|
||||||
hasBeenRun = true
|
hasBeenRun = true
|
||||||
null
|
null
|
||||||
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, false)
|
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, false)
|
||||||
|
@ -376,7 +377,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
//LOOP ENABLE : from disabled
|
//LOOP ENABLE : from disabled
|
||||||
hasBeenRun = false
|
hasBeenRun = false
|
||||||
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false)
|
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false)
|
||||||
PowerMockito.doAnswer(Answer { _: InvocationOnMock? ->
|
PowerMockito.doAnswer(Answer {
|
||||||
hasBeenRun = true
|
hasBeenRun = true
|
||||||
null
|
null
|
||||||
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, true)
|
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, true)
|
||||||
|
@ -660,11 +661,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processProfileTest() {
|
@Test fun processProfileTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
//PROFILE
|
//PROFILE
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "PROFILE")
|
var sms = Sms("1234", "PROFILE")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
@ -699,7 +699,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
sms = Sms("1234", "PROFILE LIST")
|
sms = Sms("1234", "PROFILE LIST")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("1. " + TESTPROFILENAME, smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("1. $TESTPROFILENAME", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
|
||||||
//PROFILE 2 (non existing)
|
//PROFILE 2 (non existing)
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -742,11 +742,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processBasalTest() {
|
@Test fun processBasalTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
//BASAL
|
//BASAL
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "BASAL")
|
var sms = Sms("1234", "BASAL")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
@ -817,7 +816,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0))
|
||||||
|
|
||||||
//BASAL 1 20
|
//BASAL 1 20
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -825,7 +824,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0))
|
||||||
|
|
||||||
//BASAL 1 30
|
//BASAL 1 30
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -840,11 +839,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processExtendedTest() {
|
@Test fun processExtendedTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
//EXTENDED
|
//EXTENDED
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "EXTENDED")
|
var sms = Sms("1234", "EXTENDED")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
@ -874,7 +872,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||||
|
|
||||||
//EXTENDED 1 0
|
//EXTENDED 1 0
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -896,11 +894,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processBolusTest() {
|
@Test fun processBolusTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
//BOLUS
|
//BOLUS
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "BOLUS")
|
var sms = Sms("1234", "BOLUS")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
@ -912,7 +909,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||||
PowerMockito.`when`(DateUtil.now()).thenReturn(1000L)
|
PowerMockito.`when`(DateUtil.now()).thenReturn(1000L)
|
||||||
`when`(sp.getLong(R.string.key_smscommunicator_remotebolusmindistance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L)
|
`when`(sp.getLong(R.string.key_smscommunicator_remotebolusmindistance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L)
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
|
@ -921,7 +918,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint<Double>(0.0))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
|
||||||
PowerMockito.`when`(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L)
|
PowerMockito.`when`(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L)
|
||||||
|
|
||||||
//BOLUS 0
|
//BOLUS 0
|
||||||
|
@ -937,8 +934,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||||
|
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -953,13 +950,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
//BOLUS 1 (Suspended pump)
|
//BOLUS 1 (Suspended pump)
|
||||||
smsCommunicatorPlugin.lastRemoteBolusTime = 0
|
smsCommunicatorPlugin.lastRemoteBolusTime = 0
|
||||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(true)
|
PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(true)
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "BOLUS 1")
|
sms = Sms("1234", "BOLUS 1")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
|
||||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(false)
|
PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(false)
|
||||||
|
|
||||||
//BOLUS 1 a
|
//BOLUS 1 a
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -982,11 +979,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processCalTest() {
|
@Test fun processCalTest() {
|
||||||
var sms: Sms
|
|
||||||
|
|
||||||
//CAL
|
//CAL
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "CAL")
|
var sms = Sms("1234", "CAL")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("CAL", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("CAL", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
@ -1019,12 +1015,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun processCarbsTest() {
|
@Test fun processCarbsTest() {
|
||||||
var sms: Sms
|
|
||||||
PowerMockito.`when`(DateUtil.now()).thenReturn(1000000L)
|
PowerMockito.`when`(DateUtil.now()).thenReturn(1000000L)
|
||||||
`when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false)
|
`when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false)
|
||||||
//CAL
|
//CAL
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "CARBS")
|
var sms = Sms("1234", "CARBS")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertEquals("CARBS", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("CARBS", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||||
|
|
|
@ -16,12 +16,12 @@ import org.json.JSONObject
|
||||||
*/
|
*/
|
||||||
interface PumpInterface {
|
interface PumpInterface {
|
||||||
|
|
||||||
val isInitialized: Boolean // true if pump status has been read and is ready to accept commands
|
fun isInitialized(): Boolean // true if pump status has been read and is ready to accept commands
|
||||||
val isSuspended: Boolean // true if suspended (not delivering insulin)
|
fun isSuspended(): Boolean // true if suspended (not delivering insulin)
|
||||||
val isBusy: Boolean // if true pump is not ready to accept commands right now
|
fun isBusy(): Boolean // if true pump is not ready to accept commands right now
|
||||||
val isConnected: Boolean // true if BT connection is established
|
fun isConnected(): Boolean // true if BT connection is established
|
||||||
val isConnecting: Boolean // true if BT connection is in progress
|
fun isConnecting(): Boolean // true if BT connection is in progress
|
||||||
val isHandshakeInProgress: Boolean // true if BT is connected but initial handshake is still in progress
|
fun isHandshakeInProgress(): Boolean // true if BT is connected but initial handshake is still in progress
|
||||||
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
|
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
|
||||||
fun connect(reason: String)
|
fun connect(reason: String)
|
||||||
fun disconnect(reason: String)
|
fun disconnect(reason: String)
|
||||||
|
|
|
@ -141,9 +141,9 @@ class DanaRSPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val isConnected: Boolean = danaRSService?.isConnected ?: false
|
override fun isConnected(): Boolean = danaRSService?.isConnected ?: false
|
||||||
override val isConnecting: Boolean = danaRSService?.isConnecting ?: false
|
override fun isConnecting(): Boolean = danaRSService?.isConnecting ?: false
|
||||||
override val isHandshakeInProgress: Boolean = false
|
override fun isHandshakeInProgress(): Boolean = false
|
||||||
|
|
||||||
override fun disconnect(reason: String) {
|
override fun disconnect(reason: String) {
|
||||||
aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason")
|
aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason")
|
||||||
|
@ -195,18 +195,18 @@ class DanaRSPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pump interface
|
// Pump interface
|
||||||
override val isInitialized: Boolean =
|
override fun isInitialized(): Boolean =
|
||||||
danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK
|
danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK
|
||||||
|
|
||||||
override val isSuspended: Boolean =
|
override fun isSuspended(): Boolean =
|
||||||
danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE
|
danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE
|
||||||
|
|
||||||
override val isBusy: Boolean =
|
override fun isBusy(): Boolean =
|
||||||
danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false
|
danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false
|
||||||
|
|
||||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||||
val result = PumpEnactResult(injector)
|
val result = PumpEnactResult(injector)
|
||||||
if (!isInitialized) {
|
if (!isInitialized()) {
|
||||||
aapsLogger.error("setNewBasalProfile not initialized")
|
aapsLogger.error("setNewBasalProfile not initialized")
|
||||||
val notification = Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT)
|
val notification = Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT)
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
|
@ -233,7 +233,7 @@ class DanaRSPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean {
|
override fun isThisProfileSet(profile: Profile): Boolean {
|
||||||
if (!isInitialized) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
if (!isInitialized()) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||||
if (danaPump.pumpProfiles == null) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
if (danaPump.pumpProfiles == null) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||||
val basalValues = if (danaPump.basal48Enable) 48 else 24
|
val basalValues = if (danaPump.basal48Enable) 48 else 24
|
||||||
val basalIncrement = if (danaPump.basal48Enable) 30 * 60 else 60 * 60
|
val basalIncrement = if (danaPump.basal48Enable) 30 * 60 else 60 * 60
|
||||||
|
@ -410,8 +410,7 @@ class DanaRSPlugin @Inject constructor(
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set")
|
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
val connectionOK: Boolean
|
val connectionOK: Boolean = if (durationInMinutes == 15 || durationInMinutes == 30) {
|
||||||
connectionOK = if (durationInMinutes == 15 || durationInMinutes == 30) {
|
|
||||||
danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes)
|
danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes)
|
||||||
?: false
|
?: false
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -176,15 +176,19 @@ class DanaRSService : DaggerService() {
|
||||||
rxBus.send(EventInitializationChanged())
|
rxBus.send(EventInitializationChanged())
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if (danaPump.usingUTC) {
|
when {
|
||||||
|
danaPump.usingUTC -> {
|
||||||
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset))
|
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset))
|
||||||
} else if (danaPump.protocol >= 6) { // can set seconds
|
}
|
||||||
|
danaPump.protocol >= 6 -> { // can set seconds
|
||||||
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now()))
|
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now()))
|
||||||
} else {
|
}
|
||||||
|
else -> {
|
||||||
waitForWholeMinute() // Dana can set only whole minute
|
waitForWholeMinute() // Dana can set only whole minute
|
||||||
// add 10sec to be sure we are over minute (will be cut off anyway)
|
// add 10sec to be sure we are over minute (will be cut off anyway)
|
||||||
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now() + T.secs(10).msecs()))
|
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now() + T.secs(10).msecs()))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (danaPump.usingUTC) sendMessage(DanaRS_Packet_Option_Get_Pump_UTC_And_TimeZone(injector))
|
if (danaPump.usingUTC) sendMessage(DanaRS_Packet_Option_Get_Pump_UTC_And_TimeZone(injector))
|
||||||
else sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector))
|
else sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector))
|
||||||
timeDiff = (danaPump.getPumpTime() - System.currentTimeMillis()) / 1000L
|
timeDiff = (danaPump.getPumpTime() - System.currentTimeMillis()) / 1000L
|
||||||
|
@ -211,7 +215,7 @@ class DanaRSService : DaggerService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadEvents(): PumpEnactResult {
|
fun loadEvents(): PumpEnactResult {
|
||||||
if (!danaRSPlugin.isInitialized) {
|
if (!danaRSPlugin.isInitialized()) {
|
||||||
val result = PumpEnactResult(injector).success(false)
|
val result = PumpEnactResult(injector).success(false)
|
||||||
result.comment = "pump not initialized"
|
result.comment = "pump not initialized"
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue