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, id: 0x0006, name: :on_off
attribute 0x0000, :on_off, :boolean, default: false, writable: true
attribute 0xFFFD, :cluster_revision, :uint16, default: 4
command 0x00, :off, []
command 0x01, :on, []
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
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()]