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(
|
||||
context,
|
||||
rh.gs(R.string.run_question, event.title),
|
||||
{ handler.post { automationPlugin.processEvent(event, true) } }
|
||||
{ handler.post { automationPlugin.processEvent(event) } }
|
||||
)
|
||||
}
|
||||
binding.buttonsLayout.userButtonsLayout.addView(it)
|
||||
|
|
|
@ -186,18 +186,18 @@ class AutomationPlugin @Inject constructor(
|
|||
|
||||
@Synchronized
|
||||
private fun processActions() {
|
||||
var userEventsEnabled = config.APS
|
||||
if (config.APS) {
|
||||
var commonEventsEnabled = true
|
||||
if (loopPlugin.isSuspended || !(loopPlugin as PluginBase).isEnabled()) {
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Loop deactivated")
|
||||
executionLog.add(rh.gs(R.string.loopisdisabled))
|
||||
userEventsEnabled = false
|
||||
rxBus.send(EventAutomationUpdateGui())
|
||||
commonEventsEnabled = false
|
||||
}
|
||||
val enabled = constraintChecker.isAutomationEnabled()
|
||||
if (!enabled.value()) {
|
||||
executionLog.add(enabled.getMostLimitedReasons(aapsLogger))
|
||||
userEventsEnabled = false
|
||||
}
|
||||
rxBus.send(EventAutomationUpdateGui())
|
||||
commonEventsEnabled = false
|
||||
}
|
||||
|
||||
aapsLogger.debug(LTag.AUTOMATION, "processActions")
|
||||
|
@ -205,7 +205,7 @@ class AutomationPlugin @Inject constructor(
|
|||
while (iterator.hasNext()) {
|
||||
val event = iterator.next()
|
||||
if (event.isEnabled && !event.userAction && event.shouldRun())
|
||||
processEvent(event, userEventsEnabled)
|
||||
if (event.systemAction || commonEventsEnabled) processEvent(event)
|
||||
}
|
||||
// we cannot detect connected BT devices
|
||||
// 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
|
||||
}
|
||||
|
||||
fun processEvent(event: AutomationEvent, userEventsEnabled: Boolean) {
|
||||
fun processEvent(event: AutomationEvent) {
|
||||
if (event.trigger.shouldRun() && event.getPreconditions().shouldRun()) {
|
||||
if (event.systemAction || userEventsEnabled) {
|
||||
val actions = event.actions
|
||||
for (action in actions) {
|
||||
action.title = event.title
|
||||
|
@ -226,15 +225,15 @@ class AutomationPlugin @Inject constructor(
|
|||
action.doAction(object : Callback() {
|
||||
override fun run() {
|
||||
val sb = StringBuilder()
|
||||
sb.append(dateUtil.timeString(dateUtil.now()))
|
||||
sb.append(" ")
|
||||
sb.append(if (result.success) "☺" else "▼")
|
||||
sb.append(" <b>")
|
||||
sb.append(event.title)
|
||||
sb.append(":</b> ")
|
||||
sb.append(action.shortDescription())
|
||||
sb.append(": ")
|
||||
sb.append(result.comment)
|
||||
.append(dateUtil.timeString(dateUtil.now()))
|
||||
.append(" ")
|
||||
.append(if (result.success) "☺" else "▼")
|
||||
.append(" <b>")
|
||||
.append(event.title)
|
||||
.append(":</b> ")
|
||||
.append(action.shortDescription())
|
||||
.append(": ")
|
||||
.append(result.comment)
|
||||
executionLog.add(sb.toString())
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Executed: $sb")
|
||||
rxBus.send(EventAutomationUpdateGui())
|
||||
|
@ -251,7 +250,6 @@ class AutomationPlugin @Inject constructor(
|
|||
if (event.autoRemove) automationEvents.remove(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun add(event: AutomationEvent) {
|
||||
|
@ -306,7 +304,7 @@ class AutomationPlugin @Inject constructor(
|
|||
val iterator: MutableIterator<AutomationEvent> = automationEvents.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val event = iterator.next()
|
||||
if (event.userAction) list.add(event)
|
||||
if (event.userAction && event.isEnabled) list.add(event)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue