MatterEx.Cluster behaviour (matter_ex v0.3.0)

Copy Markdown View Source

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

attr_def()

@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
}

cmd_def()

@type cmd_def() :: %{id: non_neg_integer(), name: atom(), params: keyword()}

event_def()

@type event_def() :: %{
  id: non_neg_integer(),
  name: atom(),
  priority: non_neg_integer()
}

Callbacks

attribute_defs()

@callback attribute_defs() :: [attr_def()]

cluster_id()

@callback cluster_id() :: non_neg_integer()

cluster_name()

@callback cluster_name() :: atom()

command_defs()

@callback command_defs() :: [cmd_def()]

event_defs()

@callback event_defs() :: [event_def()]

handle_command(atom, map, map)

@callback handle_command(atom(), map(), map()) ::
  {:ok, term() | nil, map()} | {:error, atom()}

Functions

attribute(id, name, type, opts)

(macro)

attribute(id, name, type, default_opts, write_opts)

(macro)

command(id, name, params)

(macro)

command(id, name, params, opts)

(macro)

event(id, name, priority)

(macro)