remove :automation dependency

This commit is contained in:
Milos Kozak 2022-12-09 10:16:38 +01:00
parent e2f96fd70d
commit d34bcbf74f
16 changed files with 190 additions and 254 deletions

View file

@ -79,7 +79,6 @@
<string name="authorizationfailed">Authorization failed</string> <string name="authorizationfailed">Authorization failed</string>
<string name="copytolocalprofile_invalid">Unable to create profile. Profile is invalid.</string> <string name="copytolocalprofile_invalid">Unable to create profile. Profile is invalid.</string>
<string name="cta_dont_kill_my_app_info">Don\'t kill my app?</string> <string name="cta_dont_kill_my_app_info">Don\'t kill my app?</string>
<string name="time_to_eat">Time to eat!\nRun Bolus wizard and do calculation again.</string>
<string name="fabric_upload_disabled">Crash logs upload disabled!</string> <string name="fabric_upload_disabled">Crash logs upload disabled!</string>
<string name="clear_filter">Clear filter</string> <string name="clear_filter">Clear filter</string>
<string name="cannula">Cannula</string> <string name="cannula">Cannula</string>

View file

@ -1,14 +0,0 @@
package info.nightscout.interfaces
interface BolusTimer {
/**
* Create new Automation event to alarm when is time to bolus
*/
fun scheduleAutomationEventBolusReminder()
/**
* Remove Automation event
*/
fun removeAutomationEventBolusReminder()
}

View file

@ -1,21 +0,0 @@
package info.nightscout.interfaces
interface CarbTimer {
/**
* Generate reminder via [info.nightscout.androidaps.utils.TimerUtil]
*
* @param seconds seconds to the future
*/
fun scheduleTimeToEatReminder(seconds: Int)
/**
* Create new Automation event to alarm when is time to eat
*/
fun scheduleAutomationEventEatReminder()
/**
* Remove Automation event
*/
fun removeAutomationEventEatReminder()
}

View file

@ -1,6 +1,36 @@
package info.nightscout.interfaces.automation package info.nightscout.interfaces.automation
interface Automation { interface Automation {
fun userEvents(): List<AutomationEvent> fun userEvents(): List<AutomationEvent>
fun processEvent(someEvent: AutomationEvent) fun processEvent(someEvent: AutomationEvent)
/**
* Generate reminder via [info.nightscout.interfaces.utils.TimerUtil]
*
*/
fun scheduleAutomationEventBolusReminder()
/**
* Remove scheduled reminder from automations
*
*/
fun removeAutomationEventBolusReminder()
/**
* Generate reminder via [info.nightscout.interfaces.utils.TimerUtil]
*
* @param seconds seconds to the future
*/
fun scheduleTimeToEatReminder(seconds: Int)
/**
* Remove Automation event
*/
fun removeAutomationEventEatReminder()
/**
* Create new Automation event to alarm when is time to eat
*/
fun scheduleAutomationEventEatReminder()
} }

View file

@ -15,10 +15,9 @@ import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Action
import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.UserEntry.Sources
import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.automation.Automation
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.db.PersistenceLayer
@ -69,8 +68,7 @@ class BolusWizard @Inject constructor(
@Inject lateinit var dateUtil: DateUtil @Inject lateinit var dateUtil: DateUtil
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var carbTimer: CarbTimer @Inject lateinit var automation: Automation
@Inject lateinit var bolusTimer: BolusTimer
@Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider
@Inject lateinit var uiInteraction: UiInteraction @Inject lateinit var uiInteraction: UiInteraction
@Inject lateinit var persistenceLayer: PersistenceLayer @Inject lateinit var persistenceLayer: PersistenceLayer
@ -361,9 +359,9 @@ class BolusWizard @Inject constructor(
} }
accepted = true accepted = true
if (calculatedTotalInsulin > 0.0) if (calculatedTotalInsulin > 0.0)
bolusTimer.removeAutomationEventBolusReminder() automation.removeAutomationEventBolusReminder()
if (carbs > 0.0) if (carbs > 0.0)
carbTimer.removeAutomationEventEatReminder() automation.removeAutomationEventEatReminder()
if (sp.getBoolean(info.nightscout.core.ui.R.string.key_usebolusadvisor, false) && Profile.toMgdl(bg, profile.units) > 180 && carbs > 0 && carbTime >= 0) if (sp.getBoolean(info.nightscout.core.ui.R.string.key_usebolusadvisor, false) && Profile.toMgdl(bg, profile.units) > 180 && carbs > 0 && carbTime >= 0)
OKDialog.showYesNoCancel(ctx, rh.gs(info.nightscout.core.ui.R.string.bolus_advisor), rh.gs(info.nightscout.core.ui.R.string.bolus_advisor_message), OKDialog.showYesNoCancel(ctx, rh.gs(info.nightscout.core.ui.R.string.bolus_advisor), rh.gs(info.nightscout.core.ui.R.string.bolus_advisor_message),
{ bolusAdvisorProcessing(ctx) }, { bolusAdvisorProcessing(ctx) },
@ -402,7 +400,7 @@ class BolusWizard @Inject constructor(
if (!result.success) { if (!result.success) {
uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror)
} else } else
carbTimer.scheduleAutomationEventEatReminder() automation.scheduleAutomationEventEatReminder()
} }
}) })
} }
@ -494,7 +492,7 @@ class BolusWizard @Inject constructor(
bolusCalculatorResult?.let { persistenceLayer.insertOrUpdate(it) } bolusCalculatorResult?.let { persistenceLayer.insertOrUpdate(it) }
} }
if (useAlarm && carbs > 0 && carbTime > 0) { if (useAlarm && carbs > 0 && carbTime > 0) {
carbTimer.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt())
} }
} }
}) })

View file

@ -19,7 +19,6 @@ dependencies {
implementation project(':app-wear-shared:shared') implementation project(':app-wear-shared:shared')
implementation project(':database:entities') implementation project(':database:entities')
implementation project(':database:impl') implementation project(':database:impl')
implementation project(':plugins:automation')
implementation project(':core:main') implementation project(':core:main')
implementation project(':core:graph') implementation project(':core:graph')
implementation project(':core:graphview') implementation project(':core:graphview')

View file

@ -1,55 +0,0 @@
package info.nightscout.implementation
import dagger.android.HasAndroidInjector
import info.nightscout.automation.AutomationEventObject
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.actions.ActionAlarm
import info.nightscout.automation.elements.Comparator
import info.nightscout.automation.elements.InputDelta
import info.nightscout.automation.triggers.TriggerBg
import info.nightscout.automation.triggers.TriggerConnector
import info.nightscout.automation.triggers.TriggerDelta
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.shared.interfaces.ResourceHelper
import java.text.DecimalFormat
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BolusTimerImpl @Inject constructor(
private val injector: HasAndroidInjector,
private val rh: ResourceHelper,
private val automationPlugin: AutomationPlugin,
) : BolusTimer {
override fun scheduleAutomationEventBolusReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder)
readOnly = true
systemAction = true
autoRemove = true
trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply {
// Bg above 70 mgdl and delta positive mgdl
list.add(TriggerBg(injector, 70.0, GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_GREATER))
list.add(
TriggerDelta(
injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare
.IS_GREATER
)
)
}
actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_bolus)))
}
automationPlugin.addIfNotExists(event)
}
override fun removeAutomationEventBolusReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder)
}
automationPlugin.removeIfExists(event)
}
}

View file

@ -1,102 +0,0 @@
package info.nightscout.implementation
import dagger.android.HasAndroidInjector
import info.nightscout.automation.AutomationEventObject
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.actions.ActionAlarm
import info.nightscout.automation.elements.Comparator
import info.nightscout.automation.elements.InputDelta
import info.nightscout.automation.triggers.TriggerBg
import info.nightscout.automation.triggers.TriggerConnector
import info.nightscout.automation.triggers.TriggerDelta
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.utils.TimerUtil
import info.nightscout.shared.interfaces.ResourceHelper
import java.text.DecimalFormat
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class CarbTimerImpl @Inject constructor(
private val injector: HasAndroidInjector,
private val rh: ResourceHelper,
private val automationPlugin: AutomationPlugin,
private val timerUtil: TimerUtil
) : CarbTimer {
/**
* Generate reminder via [info.nightscout.androidaps.utils.TimerUtil]
*
* @param seconds seconds to the future
*/
override fun scheduleTimeToEatReminder(seconds: Int) =
timerUtil.scheduleReminder(seconds, rh.gs(R.string.time_to_eat))
/**
* Create new Automation event to alarm when is time to eat
*/
override fun scheduleAutomationEventEatReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor)
readOnly = true
systemAction = true
autoRemove = true
trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply {
// Bg under 180 mgdl and dropping by 15 mgdl
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 180.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
// Bg under 160 mgdl and dropping by 9 mgdl
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 160.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
// Bg under 145 mgdl and dropping
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 145.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
}
actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_eat)))
}
automationPlugin.addIfNotExists(event)
}
/**
* Remove Automation event
*/
override fun removeAutomationEventEatReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor)
}
automationPlugin.removeIfExists(event)
}
}

View file

@ -4,8 +4,6 @@ import dagger.Binds
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.OverviewData
import info.nightscout.implementation.BolusTimerImpl
import info.nightscout.implementation.CarbTimerImpl
import info.nightscout.implementation.DefaultValueHelperImpl import info.nightscout.implementation.DefaultValueHelperImpl
import info.nightscout.implementation.HardLimitsImpl import info.nightscout.implementation.HardLimitsImpl
import info.nightscout.implementation.LocalAlertUtilsImpl import info.nightscout.implementation.LocalAlertUtilsImpl
@ -40,8 +38,6 @@ import info.nightscout.implementation.stats.TddCalculatorImpl
import info.nightscout.implementation.stats.TirCalculatorImpl import info.nightscout.implementation.stats.TirCalculatorImpl
import info.nightscout.implementation.storage.FileStorage import info.nightscout.implementation.storage.FileStorage
import info.nightscout.implementation.userEntry.UserEntryPresentationHelperImpl import info.nightscout.implementation.userEntry.UserEntryPresentationHelperImpl
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.LocalAlertUtils import info.nightscout.interfaces.LocalAlertUtils
import info.nightscout.interfaces.NotificationHolder import info.nightscout.interfaces.NotificationHolder
import info.nightscout.interfaces.Translator import info.nightscout.interfaces.Translator
@ -113,8 +109,6 @@ abstract class ImplementationModule {
@Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator @Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator
@Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync @Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync
@Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast @Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast
@Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer
@Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer
@Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils @Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider @Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder @Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder

View file

@ -5,8 +5,6 @@
<string name="bg_label">BG</string> <string name="bg_label">BG</string>
<string name="time_to_eat">Time to eat</string>
<string name="time_to_bolus">Time to bolus!\nRun Bolus wizard and do calculation again.</string>
<string name="executing_right_now">Command is executed right now</string> <string name="executing_right_now">Command is executed right now</string>
<string name="basal_value_below_minimum">Basal value below minimum. Profile not set!</string> <string name="basal_value_below_minimum">Basal value below minimum. Profile not set!</string>
<string name="permission">Permission</string> <string name="permission">Permission</string>

View file

@ -17,6 +17,8 @@ import info.nightscout.automation.actions.ActionSendSMS
import info.nightscout.automation.actions.ActionStartTempTarget import info.nightscout.automation.actions.ActionStartTempTarget
import info.nightscout.automation.actions.ActionStopProcessing import info.nightscout.automation.actions.ActionStopProcessing
import info.nightscout.automation.actions.ActionStopTempTarget import info.nightscout.automation.actions.ActionStopTempTarget
import info.nightscout.automation.elements.Comparator
import info.nightscout.automation.elements.InputDelta
import info.nightscout.automation.events.EventAutomationDataChanged import info.nightscout.automation.events.EventAutomationDataChanged
import info.nightscout.automation.events.EventAutomationUpdateGui import info.nightscout.automation.events.EventAutomationUpdateGui
import info.nightscout.automation.events.EventLocationChange import info.nightscout.automation.events.EventLocationChange
@ -41,6 +43,7 @@ import info.nightscout.automation.triggers.TriggerTimeRange
import info.nightscout.automation.triggers.TriggerWifiSsid import info.nightscout.automation.triggers.TriggerWifiSsid
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.automation.Automation import info.nightscout.interfaces.automation.Automation
import info.nightscout.interfaces.automation.AutomationEvent import info.nightscout.interfaces.automation.AutomationEvent
@ -50,6 +53,7 @@ import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Callback
import info.nightscout.interfaces.utils.TimerUtil
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventBTChange import info.nightscout.rx.events.EventBTChange
@ -67,6 +71,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.text.DecimalFormat
import java.util.Collections import java.util.Collections
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -87,7 +92,8 @@ class AutomationPlugin @Inject constructor(
private val config: Config, private val config: Config,
private val locationServiceHelper: LocationServiceHelper, private val locationServiceHelper: LocationServiceHelper,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val activePlugin: ActivePlugin private val activePlugin: ActivePlugin,
private val timerUtil: TimerUtil
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
@ -402,4 +408,109 @@ class AutomationPlugin @Inject constructor(
TriggerBTDevice(injector), TriggerBTDevice(injector),
) )
} }
/**
* Generate reminder via [info.nightscout.interfaces.utils.TimerUtil]
*
* @param seconds seconds to the future
*/
override fun scheduleTimeToEatReminder(seconds: Int) =
timerUtil.scheduleReminder(seconds, rh.gs(R.string.time_to_eat))
/**
* Create new Automation event to alarm when is time to eat
*/
override fun scheduleAutomationEventEatReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor)
readOnly = true
systemAction = true
autoRemove = true
trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply {
// Bg under 180 mgdl and dropping by 15 mgdl
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 180.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
// Bg under 160 mgdl and dropping by 9 mgdl
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 160.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
// Bg under 145 mgdl and dropping
list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply {
list.add(TriggerBg(injector, 145.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER))
list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER))
list.add(
TriggerDelta(
injector,
InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE),
GlucoseUnit.MGDL,
Comparator.Compare.IS_EQUAL_OR_LESSER
)
)
})
}
actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_eat)))
}
addIfNotExists(event)
}
/**
* Remove Automation event
*/
override fun removeAutomationEventEatReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor)
}
removeIfExists(event)
}
override fun scheduleAutomationEventBolusReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder)
readOnly = true
systemAction = true
autoRemove = true
trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply {
// Bg above 70 mgdl and delta positive mgdl
list.add(TriggerBg(injector, 70.0, GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_GREATER))
list.add(
TriggerDelta(
injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare
.IS_GREATER
)
)
}
actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_bolus)))
}
addIfNotExists(event)
}
override fun removeAutomationEventBolusReminder() {
val event = AutomationEventObject(injector).apply {
title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder)
}
removeIfExists(event)
}
} }

View file

@ -131,4 +131,8 @@
<string name="saturday_short">S</string> <string name="saturday_short">S</string>
<string name="sunday_short">S</string> <string name="sunday_short">S</string>
<!-- Reminders-->
<string name="time_to_eat">Time to eat!\nRun Bolus wizard and do calculation again.</string>
<string name="time_to_bolus">Time to bolus!\nRun Bolus wizard and do calculation again.</string>
</resources> </resources>

View file

@ -1,10 +1,9 @@
package info.nightscout.implementation package info.nightscout.automation
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.services.LocationServiceHelper import info.nightscout.automation.services.LocationServiceHelper
import info.nightscout.automation.triggers.Trigger import info.nightscout.automation.triggers.Trigger
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
@ -14,16 +13,17 @@ import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.utils.TimerUtil
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.anyInt import org.mockito.Mockito
import org.mockito.Mockito.`when`
class BolusTimerImplTest : TestBase() { class BolusTimerImplTest : TestBase() {
@ -38,6 +38,7 @@ class BolusTimerImplTest : TestBase() {
@Mock lateinit var locationServiceHelper: LocationServiceHelper @Mock lateinit var locationServiceHelper: LocationServiceHelper
@Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var timerUtil: TimerUtil
private val injector = HasAndroidInjector { private val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -50,23 +51,22 @@ class BolusTimerImplTest : TestBase() {
private lateinit var dateUtil: DateUtil private lateinit var dateUtil: DateUtil
private lateinit var automationPlugin: AutomationPlugin private lateinit var automationPlugin: AutomationPlugin
private lateinit var sut: BolusTimerImpl
@BeforeEach @BeforeEach
fun init() { fun init() {
`when`(rh.gs(anyInt())).thenReturn("") Mockito.`when`(rh.gs(anyInt())).thenReturn("")
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin) automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
sut = BolusTimerImpl(injector, rh, automationPlugin) activePlugin, timerUtil)
} }
@Test @Test
fun doTest() { fun doTest() {
Assert.assertEquals(0, automationPlugin.size()) Assertions.assertEquals(0, automationPlugin.size())
sut.scheduleAutomationEventBolusReminder() automationPlugin.scheduleAutomationEventBolusReminder()
Assert.assertEquals(1, automationPlugin.size()) Assertions.assertEquals(1, automationPlugin.size())
sut.removeAutomationEventBolusReminder() automationPlugin.removeAutomationEventBolusReminder()
Assert.assertEquals(0, automationPlugin.size()) Assertions.assertEquals(0, automationPlugin.size())
} }
} }

View file

@ -1,10 +1,9 @@
package info.nightscout.implementation package info.nightscout.automation
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.services.LocationServiceHelper import info.nightscout.automation.services.LocationServiceHelper
import info.nightscout.automation.triggers.Trigger import info.nightscout.automation.triggers.Trigger
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
@ -19,14 +18,13 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
import org.junit.Assert import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.`when`
class CarbTimerImplTest : TestBase() { class CarbTimerImplTest : TestBase() {
@ -54,27 +52,26 @@ class CarbTimerImplTest : TestBase() {
private lateinit var timerUtil: TimerUtil private lateinit var timerUtil: TimerUtil
private lateinit var automationPlugin: AutomationPlugin private lateinit var automationPlugin: AutomationPlugin
private lateinit var sut: CarbTimerImpl
@BeforeEach @BeforeEach
fun init() { fun init() {
`when`(rh.gs(anyInt())).thenReturn("") Mockito.`when`(rh.gs(anyInt())).thenReturn("")
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
dateUtil = DateUtil(context) dateUtil = DateUtil(context)
timerUtil = TimerUtil(context) timerUtil = TimerUtil(context)
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin) automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
sut = CarbTimerImpl(injector, rh, automationPlugin, timerUtil) activePlugin, timerUtil)
} }
@Test @Test
fun doTest() { fun doTest() {
Assert.assertEquals(0, automationPlugin.size()) Assertions.assertEquals(0, automationPlugin.size())
sut.scheduleAutomationEventEatReminder() automationPlugin.scheduleAutomationEventEatReminder()
Assert.assertEquals(1, automationPlugin.size()) Assertions.assertEquals(1, automationPlugin.size())
sut.removeAutomationEventEatReminder() automationPlugin.removeAutomationEventEatReminder()
Assert.assertEquals(0, automationPlugin.size()) Assertions.assertEquals(0, automationPlugin.size())
sut.scheduleTimeToEatReminder(1) automationPlugin.scheduleTimeToEatReminder(1)
Mockito.verify(context, Mockito.times(1)).startActivity(any()) Mockito.verify(context, Mockito.times(1)).startActivity(any())
} }
} }

View file

@ -17,12 +17,11 @@ import info.nightscout.database.entities.UserEntry.Sources
import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.CarbTimer
import info.nightscout.interfaces.Constants.CARBS_FAV1_DEFAULT import info.nightscout.interfaces.Constants.CARBS_FAV1_DEFAULT
import info.nightscout.interfaces.Constants.CARBS_FAV2_DEFAULT import info.nightscout.interfaces.Constants.CARBS_FAV2_DEFAULT
import info.nightscout.interfaces.Constants.CARBS_FAV3_DEFAULT import info.nightscout.interfaces.Constants.CARBS_FAV3_DEFAULT
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.automation.Automation
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.iob.GlucoseStatusProvider import info.nightscout.interfaces.iob.GlucoseStatusProvider
@ -62,8 +61,7 @@ class CarbsDialog : DialogFragmentWithDate() {
@Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var iobCobCalculator: IobCobCalculator
@Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var carbTimer: CarbTimer @Inject lateinit var automation: Automation
@Inject lateinit var bolusTimer: BolusTimer
@Inject lateinit var commandQueue: CommandQueue @Inject lateinit var commandQueue: CommandQueue
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var protectionCheck: ProtectionCheck
@ -372,16 +370,16 @@ class CarbsDialog : DialogFragmentWithDate() {
ValueWithUnit.Hour(duration).takeIf { duration != 0 }) ValueWithUnit.Hour(duration).takeIf { duration != 0 })
commandQueue.bolus(detailedBolusInfo, object : Callback() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
carbTimer.removeAutomationEventEatReminder() automation.removeAutomationEventEatReminder()
if (!result.success) { if (!result.success) {
uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror)
} else if (sp.getBoolean(info.nightscout.core.utils.R.string.key_usebolusreminder, false) && remindBolus) } else if (sp.getBoolean(info.nightscout.core.utils.R.string.key_usebolusreminder, false) && remindBolus)
bolusTimer.scheduleAutomationEventBolusReminder() automation.scheduleAutomationEventBolusReminder()
} }
}) })
} }
if (useAlarm && carbs > 0 && timeOffset > 0) { if (useAlarm && carbs > 0 && timeOffset > 0) {
carbTimer.scheduleTimeToEatReminder(T.mins(timeOffset.toLong()).secs().toInt()) automation.scheduleTimeToEatReminder(T.mins(timeOffset.toLong()).secs().toInt())
} }
}, null) }, null)
} }

View file

@ -16,12 +16,12 @@ import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction
import info.nightscout.interfaces.BolusTimer
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Constants.INSULIN_PLUS1_DEFAULT import info.nightscout.interfaces.Constants.INSULIN_PLUS1_DEFAULT
import info.nightscout.interfaces.Constants.INSULIN_PLUS2_DEFAULT import info.nightscout.interfaces.Constants.INSULIN_PLUS2_DEFAULT
import info.nightscout.interfaces.Constants.INSULIN_PLUS3_DEFAULT import info.nightscout.interfaces.Constants.INSULIN_PLUS3_DEFAULT
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.automation.Automation
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.db.PersistenceLayer
@ -65,7 +65,7 @@ class InsulinDialog : DialogFragmentWithDate() {
@Inject lateinit var ctx: Context @Inject lateinit var ctx: Context
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var bolusTimer: BolusTimer @Inject lateinit var automation: Automation
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var protectionCheck: ProtectionCheck
@Inject lateinit var uiInteraction: UiInteraction @Inject lateinit var uiInteraction: UiInteraction
@ -256,7 +256,7 @@ class InsulinDialog : DialogFragmentWithDate() {
ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 }) ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 })
persistenceLayer.insertOrUpdateBolus(detailedBolusInfo.createBolus()) persistenceLayer.insertOrUpdateBolus(detailedBolusInfo.createBolus())
if (timeOffset == 0) if (timeOffset == 0)
bolusTimer.removeAutomationEventBolusReminder() automation.removeAutomationEventBolusReminder()
} else { } else {
uel.log( uel.log(
UserEntry.Action.BOLUS, UserEntry.Sources.InsulinDialog, UserEntry.Action.BOLUS, UserEntry.Sources.InsulinDialog,
@ -268,7 +268,7 @@ class InsulinDialog : DialogFragmentWithDate() {
if (!result.success) { if (!result.success) {
uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror)
} else { } else {
bolusTimer.removeAutomationEventBolusReminder() automation.removeAutomationEventBolusReminder()
} }
} }
}) })