ActionStopProcessing
This commit is contained in:
parent
f560a00e8f
commit
2b0670921e
8 changed files with 106 additions and 2 deletions
|
@ -33,6 +33,7 @@ abstract class AutomationModule {
|
||||||
@ContributesAndroidInjector abstract fun triggerWifiSsidInjector(): TriggerWifiSsid
|
@ContributesAndroidInjector abstract fun triggerWifiSsidInjector(): TriggerWifiSsid
|
||||||
|
|
||||||
@ContributesAndroidInjector abstract fun actionInjector(): Action
|
@ContributesAndroidInjector abstract fun actionInjector(): Action
|
||||||
|
@ContributesAndroidInjector abstract fun actionStopProcessingInjector(): ActionStopProcessing
|
||||||
@ContributesAndroidInjector abstract fun actionLoopDisableInjector(): ActionLoopDisable
|
@ContributesAndroidInjector abstract fun actionLoopDisableInjector(): ActionLoopDisable
|
||||||
@ContributesAndroidInjector abstract fun actionLoopEnableInjector(): ActionLoopEnable
|
@ContributesAndroidInjector abstract fun actionLoopEnableInjector(): ActionLoopEnable
|
||||||
@ContributesAndroidInjector abstract fun actionLoopResumeInjector(): ActionLoopResume
|
@ContributesAndroidInjector abstract fun actionLoopResumeInjector(): ActionLoopResume
|
||||||
|
|
|
@ -4,6 +4,7 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.shared.logging.AAPSLogger
|
import info.nightscout.shared.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.Action
|
import info.nightscout.androidaps.plugins.general.automation.actions.Action
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy
|
import info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.actions.ActionStopProcessing
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
@ -52,6 +53,11 @@ class AutomationEvent(private val injector: HasAndroidInjector) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasStopProcessing(): Boolean {
|
||||||
|
for (action in actions) if (action is ActionStopProcessing) return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun toJSON(): String {
|
fun toJSON(): String {
|
||||||
val array = JSONArray()
|
val array = JSONArray()
|
||||||
for (a in actions) array.put(a.toJSON())
|
for (a in actions) array.put(a.toJSON())
|
||||||
|
|
|
@ -212,8 +212,12 @@ class AutomationPlugin @Inject constructor(
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val event = iterator.next()
|
val event = iterator.next()
|
||||||
if (event.isEnabled && !event.userAction && event.shouldRun())
|
if (event.isEnabled && !event.userAction && event.shouldRun())
|
||||||
if (event.systemAction || commonEventsEnabled) processEvent(event)
|
if (event.systemAction || commonEventsEnabled) {
|
||||||
|
processEvent(event)
|
||||||
|
if (event.hasStopProcessing()) break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we cannot detect connected BT devices
|
// we cannot detect connected BT devices
|
||||||
// so let's collect all connection/disconnections between 2 runs of processActions()
|
// so let's collect all connection/disconnections between 2 runs of processActions()
|
||||||
// TriggerBTDevice can pick up and process these events
|
// TriggerBTDevice can pick up and process these events
|
||||||
|
@ -329,6 +333,7 @@ class AutomationPlugin @Inject constructor(
|
||||||
//ActionLoopEnable(injector),
|
//ActionLoopEnable(injector),
|
||||||
//ActionLoopResume(injector),
|
//ActionLoopResume(injector),
|
||||||
//ActionLoopSuspend(injector),
|
//ActionLoopSuspend(injector),
|
||||||
|
ActionStopProcessing(injector),
|
||||||
ActionStartTempTarget(injector),
|
ActionStartTempTarget(injector),
|
||||||
ActionStopTempTarget(injector),
|
ActionStopTempTarget(injector),
|
||||||
ActionNotification(injector),
|
ActionNotification(injector),
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.androidaps.automation.R
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
class ActionStopProcessing(injector: HasAndroidInjector) : Action(injector) {
|
||||||
|
|
||||||
|
override fun friendlyName(): Int = R.string.stop_processing
|
||||||
|
override fun shortDescription(): String = rh.gs(R.string.stop_processing)
|
||||||
|
@DrawableRes override fun icon(): Int = R.drawable.ic_stop_24dp
|
||||||
|
|
||||||
|
override fun isValid(): Boolean = true
|
||||||
|
|
||||||
|
override fun doAction(callback: Callback) {
|
||||||
|
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok)).run()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toJSON(): String {
|
||||||
|
return JSONObject()
|
||||||
|
.put("type", this.javaClass.name)
|
||||||
|
.put("data", JsonObject())
|
||||||
|
.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun fromJSON(data: String): Action = this
|
||||||
|
|
||||||
|
override fun hasDialog(): Boolean = false
|
||||||
|
}
|
|
@ -126,5 +126,6 @@
|
||||||
<string name="run_automations">Run automations</string>
|
<string name="run_automations">Run automations</string>
|
||||||
<string name="add_automation">Add rule</string>
|
<string name="add_automation">Add rule</string>
|
||||||
<string name="remove_sort">Remove/sort</string>
|
<string name="remove_sort">Remove/sort</string>
|
||||||
|
<string name="stop_processing">Stop processing</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -5,13 +5,14 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.interfaces.ConfigBuilder
|
import info.nightscout.androidaps.interfaces.ConfigBuilder
|
||||||
import info.nightscout.androidaps.interfaces.Loop
|
import info.nightscout.androidaps.interfaces.Loop
|
||||||
|
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.Action
|
import info.nightscout.androidaps.plugins.general.automation.actions.Action
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable
|
import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.actions.ActionStopProcessing
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnectorTest
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnectorTest
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -70,4 +71,14 @@ class AutomationEventTest : TestBase() {
|
||||||
Assert.assertFalse(event.actions === clone.actions) // not the same object reference
|
Assert.assertFalse(event.actions === clone.actions) // not the same object reference
|
||||||
Assert.assertEquals(clone.toJSON(), clone.toJSON())
|
Assert.assertEquals(clone.toJSON(), clone.toJSON())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun hasStopProcessing() {
|
||||||
|
val event = AutomationEvent(injector)
|
||||||
|
event.title = "Test"
|
||||||
|
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest.oneItem)) as TriggerConnector
|
||||||
|
Assert.assertFalse(event.hasStopProcessing())
|
||||||
|
event.addAction(ActionStopProcessing(injector))
|
||||||
|
Assert.assertTrue(event.hasStopProcessing())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.automation.R
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
|
||||||
|
class ActionStopProcessingTest : ActionsTestBase() {
|
||||||
|
|
||||||
|
lateinit var sut: ActionStopProcessing
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
|
||||||
|
`when`(rh.gs(R.string.stop_processing)).thenReturn("Stop processing")
|
||||||
|
sut = ActionStopProcessing(injector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun friendlyNameTest() {
|
||||||
|
Assert.assertEquals(R.string.stop_processing, sut.friendlyName())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shortDescriptionTest() {
|
||||||
|
Assert.assertEquals("Stop processing", sut.shortDescription())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun iconTest() {
|
||||||
|
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun doActionTest() {
|
||||||
|
sut.doAction(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
Assert.assertTrue(result.success)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -144,6 +144,9 @@ ActionsTestBase : TestBaseWithProfile() {
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.uel = uel
|
it.uel = uel
|
||||||
}
|
}
|
||||||
|
if (it is ActionStopProcessing) {
|
||||||
|
it.rh = rh
|
||||||
|
}
|
||||||
if (it is PumpEnactResult) {
|
if (it is PumpEnactResult) {
|
||||||
it.rh = rh
|
it.rh = rh
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue