Conditions

Whilst simple, Conditions play a large role in the execution and lifecycle of an Automation. Acting as gatekeepers, Conditions decide on whether the Automation should continue and execute the Automation Action(s).

Booting

Much like Actions, they are able to asynchronously boot before being ready to execute. This is useful for fetching external data or establishing WebSocket connections as an example.

async mounted() {
    await super.mounted();

    // Establish a WebSocket connection, start longpolling, etc.
}

Execution

When a Trigger is executed in an Automation, all Conditions will be executed together, all of them needing to pass before the Automation continues to the Actions. A function inside the Condition will be called to make this check, run. It accepts a single parameter, input, which is the data output from the Trigger that executed the Automation.

Each Trigger can define it's own I/O schema, as such, it's better to test or hard-encode certain services/systems your Condition works with if you rely on the given input.

async run(input) {
    if (something) {
        /**
         * Throwing an Error is how Conditions report to the
         * App that they have failed, and as such, don't continue
         * executing the Automation.
         */
        throw new Error('You shall not pass!');
    }

    /**
     * You don't need to return anything since the function
     * is defined using `async`. Otherwise, return a resolved
     * Promise using `Promise.resolve()`
     */
}