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 pump = activePlugin.activePump
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ open class LoopPlugin @Inject constructor(
|
|||
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.loopsuspended)))
|
||||
return
|
||||
}
|
||||
if (pump.isSuspended) {
|
||||
if (pump.isSuspended()) {
|
||||
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.pumpsuspended))
|
||||
rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.pumpsuspended)))
|
||||
return
|
||||
|
@ -511,12 +511,12 @@ open class LoopPlugin @Inject constructor(
|
|||
return
|
||||
}
|
||||
val pump = activePlugin.activePump
|
||||
if (!pump.isInitialized) {
|
||||
if (!pump.isInitialized()) {
|
||||
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()
|
||||
return
|
||||
}
|
||||
if (pump.isSuspended) {
|
||||
if (pump.isSuspended()) {
|
||||
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()
|
||||
return
|
||||
|
@ -578,12 +578,12 @@ open class LoopPlugin @Inject constructor(
|
|||
.enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
if (!pump.isInitialized) {
|
||||
if (!pump.isInitialized()) {
|
||||
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()
|
||||
return
|
||||
}
|
||||
if (pump.isSuspended) {
|
||||
if (pump.isSuspended()) {
|
||||
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()
|
||||
return
|
||||
|
|
|
@ -256,10 +256,10 @@ class ActionsFragment : DaggerFragment() {
|
|||
profileSwitch?.visibility = (
|
||||
activePlugin.activeProfileInterface.profile != null &&
|
||||
pump.pumpDescription.isSetBasalProfileCapable &&
|
||||
pump.isInitialized &&
|
||||
!pump.isSuspended).toVisibility()
|
||||
pump.isInitialized() &&
|
||||
!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
|
||||
extendedBolusCancel?.visibility = View.GONE
|
||||
} 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
|
||||
cancelTempBasal?.visibility = View.GONE
|
||||
} else {
|
||||
|
@ -292,7 +292,7 @@ class ActionsFragment : DaggerFragment() {
|
|||
}
|
||||
val activeBgSource = activePlugin.activeBgSource
|
||||
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()
|
||||
tempTarget?.visibility = (profile != null && config.APS).toVisibility()
|
||||
tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility()
|
||||
|
|
|
@ -446,7 +446,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
|
||||
// QuickWizard button
|
||||
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
|
||||
val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false)
|
||||
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.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.text = "${resourceHelper.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}"
|
||||
} else {
|
||||
|
@ -471,10 +471,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
}
|
||||
|
||||
// **** 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.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.insulinButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_insulin_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.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()
|
||||
|
||||
// **** Calibration & CGM buttons ****
|
||||
val xDripIsBgSource = xdripPlugin.isEnabled(PluginType.BGSOURCE)
|
||||
|
@ -633,7 +633,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
binding.infoLayout.apsModeText.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
pump.isSuspended -> {
|
||||
pump.isSuspended() -> {
|
||||
binding.infoLayout.apsMode.setImageResource(if (pump.pumpDescription.pumpType == PumpType.Insulet_Omnipod) {
|
||||
// For Omnipod, indicate the pump as disconnected when it's suspended.
|
||||
// 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.DEVSLOPE.ordinal] -> useDSForScale = true
|
||||
}
|
||||
var 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 alignIobScale = menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.IOB.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.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.DataReceiver
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import java.text.Normalizer
|
||||
import java.util.*
|
||||
|
@ -270,7 +270,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
"BOLUS" ->
|
||||
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 && 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 sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||
"CARBS" ->
|
||||
|
|
|
@ -50,7 +50,7 @@ import javax.inject.Singleton
|
|||
class ActionStringHandler @Inject constructor(
|
||||
private val sp: SP,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val aapsSchedulers: AapsSchedulers,
|
||||
aapsSchedulers: AapsSchedulers,
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val injector: HasAndroidInjector,
|
||||
private val context: Context,
|
||||
|
@ -262,7 +262,7 @@ class ActionStringHandler @Inject constructor(
|
|||
rAction = "statusmessage"
|
||||
rMessage = "OLD DATA - "
|
||||
//if pump is not busy: try to fetch data
|
||||
if (activePump.isBusy) {
|
||||
if (activePump.isBusy()) {
|
||||
rMessage += resourceHelper.gs(R.string.pumpbusy)
|
||||
} else {
|
||||
rMessage += "trying to fetch data from pump."
|
||||
|
|
|
@ -49,12 +49,12 @@ class MDIPlugin @Inject constructor(
|
|||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||
|
||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector)
|
||||
override val isInitialized: Boolean = true
|
||||
override val isSuspended: Boolean = false
|
||||
override val isBusy: Boolean = false
|
||||
override val isConnected: Boolean = true
|
||||
override val isConnecting: Boolean = false
|
||||
override val isHandshakeInProgress: Boolean = false
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun isConnected(): Boolean = true
|
||||
override fun isConnecting(): Boolean = false
|
||||
override fun isHandshakeInProgress(): Boolean = false
|
||||
override fun connect(reason: String) {}
|
||||
override fun disconnect(reason: String) {}
|
||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||
|
|
|
@ -133,12 +133,12 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
return PumpEnactResult(injector)
|
||||
}
|
||||
|
||||
override val isInitialized: Boolean = true
|
||||
override val isSuspended: Boolean = false
|
||||
override val isBusy: Boolean = false
|
||||
override val isConnected: Boolean = true
|
||||
override val isConnecting: Boolean = false
|
||||
override val isHandshakeInProgress: Boolean = false
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun isConnected(): Boolean = true
|
||||
override fun isConnecting(): Boolean = false
|
||||
override fun isHandshakeInProgress(): Boolean = false
|
||||
|
||||
override fun connect(reason: String) {
|
||||
//if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
|
||||
|
|
|
@ -31,7 +31,6 @@ class QueueThread internal constructor(
|
|||
var waitingForDisconnect = false
|
||||
private var mWakeLock: PowerManager.WakeLock? = null
|
||||
|
||||
|
||||
init {
|
||||
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) {
|
||||
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
|
||||
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(EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout)))
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "timed out")
|
||||
|
@ -86,19 +85,19 @@ class QueueThread internal constructor(
|
|||
return
|
||||
}
|
||||
}
|
||||
if (pump.isHandshakeInProgress) {
|
||||
if (pump.isHandshakeInProgress()) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "handshaking $secondsElapsed")
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, secondsElapsed.toInt()))
|
||||
SystemClock.sleep(100)
|
||||
continue
|
||||
}
|
||||
if (pump.isConnecting) {
|
||||
if (pump.isConnecting()) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "connecting $secondsElapsed")
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
||||
SystemClock.sleep(1000)
|
||||
continue
|
||||
}
|
||||
if (!pump.isConnected) {
|
||||
if (!pump.isConnected()) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "connect")
|
||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
|
||||
pump.connect("Connection needed")
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.inject.Inject
|
|||
import kotlin.math.abs
|
||||
|
||||
class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||
|
@ -44,6 +45,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
|||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
companion object {
|
||||
|
||||
private val KEEP_ALIVE_MILLISECONDS = T.mins(5).msecs()
|
||||
private val STATUS_UPDATE_FREQUENCY = T.mins(15).msecs()
|
||||
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)) {
|
||||
rxBus.send(EventProfileNeedsUpdate())
|
||||
} else if (isStatusOutdated && !pump.isBusy) {
|
||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||
lastReadStatus = System.currentTimeMillis()
|
||||
commandQueue.readStatus("KeepAlive. Status outdated.", null)
|
||||
} else if (isBasalOutdated && !pump.isBusy) {
|
||||
} else if (isBasalOutdated && !pump.isBusy()) {
|
||||
lastReadStatus = System.currentTimeMillis()
|
||||
commandQueue.readStatus("KeepAlive. Basal outdated.", null)
|
||||
}
|
||||
|
|
|
@ -217,9 +217,11 @@ class SWDefinition @Inject constructor(
|
|||
.updateDelay(5)
|
||||
.label(R.string.treatmentssafety_maxcarbs_title)
|
||||
.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_maxcarbs, 0.0) > 0 }
|
||||
&& sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0
|
||||
}
|
||||
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
||||
.skippable(false)
|
||||
.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
|
||||
// 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)
|
||||
|
|
|
@ -14,27 +14,29 @@ import org.json.JSONObject
|
|||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface {
|
||||
|
||||
override var isConnected = false
|
||||
override var isConnecting = false
|
||||
override var isHandshakeInProgress = false
|
||||
var connected = false
|
||||
|
||||
override fun isConnected() = connected
|
||||
override fun isConnecting() = false
|
||||
override fun isHandshakeInProgress() = false
|
||||
val lastData = 0L
|
||||
|
||||
val baseBasal = 0.0
|
||||
override val pumpDescription = PumpDescription()
|
||||
|
||||
override val isInitialized: Boolean = true
|
||||
override val isSuspended: Boolean = false
|
||||
override val isBusy: Boolean = false
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun connect(reason: String) {
|
||||
isConnected = true
|
||||
connected = true
|
||||
}
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
isConnected = false
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun stopConnecting() {
|
||||
isConnected = false
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
@file:Suppress("SpellCheckingInspection")
|
||||
|
||||
package info.nightscout.androidaps.plugins.general.smsCommunicator
|
||||
|
||||
import android.content.Context
|
||||
|
@ -155,9 +157,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
||||
|
||||
`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.model()).thenReturn(PumpType.GenericAAPS);
|
||||
`when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS)
|
||||
|
||||
`when`(treatmentsPlugin.lastCalculationTreatments).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_loopisenabled)).thenReturn("Loop is enabled")
|
||||
`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_loophasbeenenabled)).thenReturn("Loop has been enabled")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)).thenReturn("Temp basal canceled")
|
||||
|
@ -241,8 +243,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
@Test
|
||||
fun processSettingsTest() {
|
||||
// called from constructor
|
||||
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers.get(0))
|
||||
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers.get(1))
|
||||
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers[0])
|
||||
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers[1])
|
||||
Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size)
|
||||
}
|
||||
|
||||
|
@ -259,17 +261,16 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.messageToConfirm = null
|
||||
}
|
||||
|
||||
@Test fun _isAllowedNumberTest() {
|
||||
@Test fun isAllowedNumberTest() {
|
||||
Assert.assertTrue(smsCommunicatorPlugin.isAllowedNumber("5678"))
|
||||
Assert.assertFalse(smsCommunicatorPlugin.isAllowedNumber("56"))
|
||||
}
|
||||
|
||||
@Test fun processSmsTest() {
|
||||
var sms: Sms
|
||||
|
||||
// SMS from not allowed number should be ignored
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("12", "aText")
|
||||
var sms = Sms("12", "aText")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertTrue(sms.ignored)
|
||||
Assert.assertEquals("aText", smsCommunicatorPlugin.messages[0].text)
|
||||
|
@ -348,7 +349,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
//LOOP DISABLE : from enabled
|
||||
hasBeenRun = false
|
||||
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
||||
PowerMockito.doAnswer(Answer { _: InvocationOnMock? ->
|
||||
PowerMockito.doAnswer(Answer {
|
||||
hasBeenRun = true
|
||||
null
|
||||
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, false)
|
||||
|
@ -376,7 +377,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
//LOOP ENABLE : from disabled
|
||||
hasBeenRun = false
|
||||
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false)
|
||||
PowerMockito.doAnswer(Answer { _: InvocationOnMock? ->
|
||||
PowerMockito.doAnswer(Answer {
|
||||
hasBeenRun = true
|
||||
null
|
||||
} as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, true)
|
||||
|
@ -660,11 +661,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processProfileTest() {
|
||||
var sms: Sms
|
||||
|
||||
//PROFILE
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PROFILE")
|
||||
var sms = Sms("1234", "PROFILE")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
@ -699,7 +699,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
sms = Sms("1234", "PROFILE LIST")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
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)
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -742,11 +742,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processBasalTest() {
|
||||
var sms: Sms
|
||||
|
||||
//BASAL
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "BASAL")
|
||||
var sms = Sms("1234", "BASAL")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
@ -817,7 +816,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
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)
|
||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint<Double>(1.0))
|
||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0))
|
||||
|
||||
//BASAL 1 20
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -825,7 +824,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
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)
|
||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint<Double>(1.0))
|
||||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0))
|
||||
|
||||
//BASAL 1 30
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -840,11 +839,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processExtendedTest() {
|
||||
var sms: Sms
|
||||
|
||||
//EXTENDED
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "EXTENDED")
|
||||
var sms = Sms("1234", "EXTENDED")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
@ -874,7 +872,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.messages[0].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
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -896,11 +894,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processBolusTest() {
|
||||
var sms: Sms
|
||||
|
||||
//BOLUS
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "BOLUS")
|
||||
var sms = Sms("1234", "BOLUS")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
@ -912,7 +909,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].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)
|
||||
`when`(sp.getLong(R.string.key_smscommunicator_remotebolusmindistance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L)
|
||||
//BOLUS 1
|
||||
|
@ -921,7 +918,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].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)
|
||||
|
||||
//BOLUS 0
|
||||
|
@ -937,8 +934,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint<Double>(1.0))
|
||||
`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0))
|
||||
|
||||
//BOLUS 1
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -953,13 +950,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
|
||||
//BOLUS 1 (Suspended pump)
|
||||
smsCommunicatorPlugin.lastRemoteBolusTime = 0
|
||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(true)
|
||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(true)
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "BOLUS 1")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
|
||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(false)
|
||||
PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(false)
|
||||
|
||||
//BOLUS 1 a
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
|
@ -982,11 +979,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processCalTest() {
|
||||
var sms: Sms
|
||||
|
||||
//CAL
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "CAL")
|
||||
var sms = Sms("1234", "CAL")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("CAL", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
@ -1019,12 +1015,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
|
||||
@Test fun processCarbsTest() {
|
||||
var sms: Sms
|
||||
PowerMockito.`when`(DateUtil.now()).thenReturn(1000000L)
|
||||
`when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false)
|
||||
//CAL
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "CARBS")
|
||||
var sms = Sms("1234", "CARBS")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertEquals("CARBS", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text)
|
||||
|
|
|
@ -16,12 +16,12 @@ import org.json.JSONObject
|
|||
*/
|
||||
interface PumpInterface {
|
||||
|
||||
val isInitialized: Boolean // true if pump status has been read and is ready to accept commands
|
||||
val isSuspended: Boolean // true if suspended (not delivering insulin)
|
||||
val isBusy: Boolean // if true pump is not ready to accept commands right now
|
||||
val isConnected: Boolean // true if BT connection is established
|
||||
val 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 isInitialized(): Boolean // true if pump status has been read and is ready to accept commands
|
||||
fun isSuspended(): Boolean // true if suspended (not delivering insulin)
|
||||
fun isBusy(): Boolean // if true pump is not ready to accept commands right now
|
||||
fun isConnected(): Boolean // true if BT connection is established
|
||||
fun isConnecting(): Boolean // true if BT connection is in progress
|
||||
fun isHandshakeInProgress(): Boolean // true if BT is connected but initial handshake is still in progress
|
||||
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
|
||||
fun connect(reason: String)
|
||||
fun disconnect(reason: String)
|
||||
|
|
|
@ -141,9 +141,9 @@ class DanaRSPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override val isConnected: Boolean = danaRSService?.isConnected ?: false
|
||||
override val isConnecting: Boolean = danaRSService?.isConnecting ?: false
|
||||
override val isHandshakeInProgress: Boolean = false
|
||||
override fun isConnected(): Boolean = danaRSService?.isConnected ?: false
|
||||
override fun isConnecting(): Boolean = danaRSService?.isConnecting ?: false
|
||||
override fun isHandshakeInProgress(): Boolean = false
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason")
|
||||
|
@ -195,18 +195,18 @@ class DanaRSPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
// Pump interface
|
||||
override val isInitialized: Boolean =
|
||||
override fun isInitialized(): Boolean =
|
||||
danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK
|
||||
|
||||
override val isSuspended: Boolean =
|
||||
override fun isSuspended(): Boolean =
|
||||
danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE
|
||||
|
||||
override val isBusy: Boolean =
|
||||
override fun isBusy(): Boolean =
|
||||
danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false
|
||||
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||
val result = PumpEnactResult(injector)
|
||||
if (!isInitialized) {
|
||||
if (!isInitialized()) {
|
||||
aapsLogger.error("setNewBasalProfile not initialized")
|
||||
val notification = Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
|
@ -233,7 +233,7 @@ class DanaRSPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
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
|
||||
val basalValues = if (danaPump.basal48Enable) 48 else 24
|
||||
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")
|
||||
return result
|
||||
}
|
||||
val connectionOK: Boolean
|
||||
connectionOK = if (durationInMinutes == 15 || durationInMinutes == 30) {
|
||||
val connectionOK: Boolean = if (durationInMinutes == 15 || durationInMinutes == 30) {
|
||||
danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes)
|
||||
?: false
|
||||
} else {
|
||||
|
|
|
@ -176,15 +176,19 @@ class DanaRSService : DaggerService() {
|
|||
rxBus.send(EventInitializationChanged())
|
||||
return
|
||||
} else {
|
||||
if (danaPump.usingUTC) {
|
||||
when {
|
||||
danaPump.usingUTC -> {
|
||||
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()))
|
||||
} else {
|
||||
}
|
||||
else -> {
|
||||
waitForWholeMinute() // Dana can set only whole minute
|
||||
// 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()))
|
||||
}
|
||||
}
|
||||
if (danaPump.usingUTC) sendMessage(DanaRS_Packet_Option_Get_Pump_UTC_And_TimeZone(injector))
|
||||
else sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector))
|
||||
timeDiff = (danaPump.getPumpTime() - System.currentTimeMillis()) / 1000L
|
||||
|
@ -211,7 +215,7 @@ class DanaRSService : DaggerService() {
|
|||
}
|
||||
|
||||
fun loadEvents(): PumpEnactResult {
|
||||
if (!danaRSPlugin.isInitialized) {
|
||||
if (!danaRSPlugin.isInitialized()) {
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
result.comment = "pump not initialized"
|
||||
return result
|
||||
|
|
Loading…
Reference in a new issue