ExMaude. IoT. Validator
(ExMaude v0.2.0)
View Source
Validates IoT rule structures before conflict detection.
This module provides validation for IoT rules, triggers, and actions before they are sent to Maude for conflict detection. Validation catches structural errors early with meaningful error messages.
Overview
Validation is performed automatically by ExMaude.IoT.detect_conflicts/2,
but can also be called directly to check rules before submission:
:ok = ExMaude.IoT.Validator.validate_rule(rule)
{:error, errors} = ExMaude.IoT.Validator.validate_rule(%{})Required Rule Fields
Every rule must have the following fields:
| Field | Type | Description |
|---|---|---|
:id | String.t() | Unique rule identifier |
:thing_id | String.t() | Target device identifier |
:trigger | trigger() | Condition that activates the rule |
:actions | [action()] | List of actions to execute |
:priority | integer() | Optional priority (default: 1) |
Trigger Validation
Valid trigger formats:
{:prop_eq, property, value}- Property equals value{:prop_gt, property, number}- Property greater than number{:prop_lt, property, number}- Property less than number{:prop_gte, property, number}- Property greater than or equal{:prop_lte, property, number}- Property less than or equal{:env_eq, property, value}- Environment equals value{:env_gt, property, number}- Environment greater than number{:env_lt, property, number}- Environment less than number{:always}- Always triggered{:and, trigger, trigger}- Logical AND{:or, trigger, trigger}- Logical OR{:not, trigger}- Logical NOT
Action Validation
Valid action formats:
{:set_prop, thing_id, property, value}- Set device property{:set_env, property, value}- Set environment variable{:invoke, thing_id, action_name}- Invoke device action
Depth Limiting
Nested triggers (:and, :or, :not) are limited to a maximum depth
of 10 to prevent infinite recursion and stack overflow.
Error Messages
Validation errors are returned as a list of human-readable strings:
{:error, [
"missing required field: id",
"missing required field: trigger",
"invalid action format"
]}Batch Validation
Use validate_rules/1 to validate multiple rules at once:
case ExMaude.IoT.Validator.validate_rules(rules) do
:ok -> proceed()
{:error, %{"rule-1" => ["invalid trigger format"]}} -> handle_errors()
endSee Also
ExMaude.IoT- High-level conflict detection APIExMaude.IoT.Encoder- Encoding validated rules to Maude syntax
Summary
Functions
Validates a rule structure.
Returns :ok if the rule is valid, or {:error, errors} with a list
of validation error messages.
Examples
:ok = validate_rule(%{
id: "my-rule",
thing_id: "device-1",
trigger: {:prop_eq, "state", true},
actions: [{:set_prop, "device-1", "power", "on"}]
})
{:error, ["missing required field: id"]} = validate_rule(%{})
Validates a list of rules.
Returns :ok if all rules are valid, or {:error, errors} with a map
of rule IDs to their validation errors.