fix processing automations
This commit is contained in:
parent
8c1b4f7534
commit
95deaf8b98
2 changed files with 44 additions and 46 deletions
|
@ -574,7 +574,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
OKDialog.showConfirmation(
|
OKDialog.showConfirmation(
|
||||||
context,
|
context,
|
||||||
rh.gs(R.string.run_question, event.title),
|
rh.gs(R.string.run_question, event.title),
|
||||||
{ handler.post { automationPlugin.processEvent(event, true) } }
|
{ handler.post { automationPlugin.processEvent(event) } }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
binding.buttonsLayout.userButtonsLayout.addView(it)
|
binding.buttonsLayout.userButtonsLayout.addView(it)
|
||||||
|
|
|
@ -186,18 +186,18 @@ class AutomationPlugin @Inject constructor(
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun processActions() {
|
private fun processActions() {
|
||||||
var userEventsEnabled = config.APS
|
var commonEventsEnabled = true
|
||||||
if (config.APS) {
|
|
||||||
if (loopPlugin.isSuspended || !(loopPlugin as PluginBase).isEnabled()) {
|
if (loopPlugin.isSuspended || !(loopPlugin as PluginBase).isEnabled()) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Loop deactivated")
|
aapsLogger.debug(LTag.AUTOMATION, "Loop deactivated")
|
||||||
executionLog.add(rh.gs(R.string.loopisdisabled))
|
executionLog.add(rh.gs(R.string.loopisdisabled))
|
||||||
userEventsEnabled = false
|
rxBus.send(EventAutomationUpdateGui())
|
||||||
|
commonEventsEnabled = false
|
||||||
}
|
}
|
||||||
val enabled = constraintChecker.isAutomationEnabled()
|
val enabled = constraintChecker.isAutomationEnabled()
|
||||||
if (!enabled.value()) {
|
if (!enabled.value()) {
|
||||||
executionLog.add(enabled.getMostLimitedReasons(aapsLogger))
|
executionLog.add(enabled.getMostLimitedReasons(aapsLogger))
|
||||||
userEventsEnabled = false
|
rxBus.send(EventAutomationUpdateGui())
|
||||||
}
|
commonEventsEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "processActions")
|
aapsLogger.debug(LTag.AUTOMATION, "processActions")
|
||||||
|
@ -205,7 +205,7 @@ 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())
|
||||||
processEvent(event, userEventsEnabled)
|
if (event.systemAction || commonEventsEnabled) processEvent(event)
|
||||||
}
|
}
|
||||||
// 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()
|
||||||
|
@ -216,9 +216,8 @@ class AutomationPlugin @Inject constructor(
|
||||||
storeToSP() // save last run time
|
storeToSP() // save last run time
|
||||||
}
|
}
|
||||||
|
|
||||||
fun processEvent(event: AutomationEvent, userEventsEnabled: Boolean) {
|
fun processEvent(event: AutomationEvent) {
|
||||||
if (event.trigger.shouldRun() && event.getPreconditions().shouldRun()) {
|
if (event.trigger.shouldRun() && event.getPreconditions().shouldRun()) {
|
||||||
if (event.systemAction || userEventsEnabled) {
|
|
||||||
val actions = event.actions
|
val actions = event.actions
|
||||||
for (action in actions) {
|
for (action in actions) {
|
||||||
action.title = event.title
|
action.title = event.title
|
||||||
|
@ -226,15 +225,15 @@ class AutomationPlugin @Inject constructor(
|
||||||
action.doAction(object : Callback() {
|
action.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
sb.append(dateUtil.timeString(dateUtil.now()))
|
.append(dateUtil.timeString(dateUtil.now()))
|
||||||
sb.append(" ")
|
.append(" ")
|
||||||
sb.append(if (result.success) "☺" else "▼")
|
.append(if (result.success) "☺" else "▼")
|
||||||
sb.append(" <b>")
|
.append(" <b>")
|
||||||
sb.append(event.title)
|
.append(event.title)
|
||||||
sb.append(":</b> ")
|
.append(":</b> ")
|
||||||
sb.append(action.shortDescription())
|
.append(action.shortDescription())
|
||||||
sb.append(": ")
|
.append(": ")
|
||||||
sb.append(result.comment)
|
.append(result.comment)
|
||||||
executionLog.add(sb.toString())
|
executionLog.add(sb.toString())
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Executed: $sb")
|
aapsLogger.debug(LTag.AUTOMATION, "Executed: $sb")
|
||||||
rxBus.send(EventAutomationUpdateGui())
|
rxBus.send(EventAutomationUpdateGui())
|
||||||
|
@ -251,7 +250,6 @@ class AutomationPlugin @Inject constructor(
|
||||||
if (event.autoRemove) automationEvents.remove(event)
|
if (event.autoRemove) automationEvents.remove(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun add(event: AutomationEvent) {
|
fun add(event: AutomationEvent) {
|
||||||
|
@ -306,7 +304,7 @@ class AutomationPlugin @Inject constructor(
|
||||||
val iterator: MutableIterator<AutomationEvent> = automationEvents.iterator()
|
val iterator: MutableIterator<AutomationEvent> = automationEvents.iterator()
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val event = iterator.next()
|
val event = iterator.next()
|
||||||
if (event.userAction) list.add(event)
|
if (event.userAction && event.isEnabled) list.add(event)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue