Behaviour and macro system for Matter clusters.
Provides a declarative DSL for defining attributes and commands. Each cluster is a GenServer holding attribute state.
Example
defmodule MyCluster do
use MatterEx.Cluster, :on_off
command :off
command :on
command :toggle
def handle_command(:off, _params, state) do
{:ok, nil, set_attribute(state, :on_off, false)}
end
def handle_command(:on, _params, state) do
{:ok, nil, set_attribute(state, :on_off, true)}
end
end
Summary
Functions
Resolves a built-in attribute name to its Matter attribute ID.
Resolves a built-in command name to its Matter command ID.
Returns the built-in cluster names accepted by use MatterEx.Cluster, name.
Resolves a built-in cluster ID to its module.
Resolves a built-in cluster name to its module.
Types
@type attr_def() :: %{ id: non_neg_integer(), name: atom(), type: atom(), default: term(), writable: boolean(), fabric_scoped: boolean(), min: number() | nil, max: number() | nil, enum_values: [non_neg_integer()] | nil }
@type cmd_def() :: %{id: non_neg_integer(), name: atom(), params: keyword()}
@type event_def() :: %{ id: non_neg_integer(), name: atom(), priority: non_neg_integer() }
Callbacks
@callback attribute_defs() :: [attr_def()]
@callback cluster_id() :: non_neg_integer()
@callback cluster_name() :: atom()
@callback command_defs() :: [cmd_def()]
@callback event_defs() :: [event_def()]
Functions
@spec attribute_id_for(atom(), atom()) :: non_neg_integer() | nil
Resolves a built-in attribute name to its Matter attribute ID.
@spec command_id_for(atom(), atom()) :: non_neg_integer() | nil
Resolves a built-in command name to its Matter command ID.
@spec known_clusters() :: [{atom(), non_neg_integer()}]
Returns the built-in cluster names accepted by use MatterEx.Cluster, name.
The returned keyword list is sorted by cluster name and maps each friendly DSL name to its Matter cluster ID.
@spec module_for_id(non_neg_integer()) :: module() | nil
Resolves a built-in cluster ID to its module.
Resolves a built-in cluster name to its module.