MatterEx.Cluster behaviour (matter_ex v0.4.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, :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

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(name, type)

(macro)

attribute(name, type, opts)

(macro)

attribute(id, name, type, opts)

(macro)

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

(macro)

attribute_id_for(cluster_name, attribute_name)

@spec attribute_id_for(atom(), atom()) :: non_neg_integer() | nil

Resolves a built-in attribute name to its Matter attribute ID.

command(name)

(macro)

command(name, opts)

(macro)

command(id, name, params)

(macro)

command(id, name, params, opts)

(macro)

command_id_for(cluster_name, command_name)

@spec command_id_for(atom(), atom()) :: non_neg_integer() | nil

Resolves a built-in command name to its Matter command ID.

event(id, name, priority)

(macro)

known_clusters()

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

module_for_id(cluster_id)

@spec module_for_id(non_neg_integer()) :: module() | nil

Resolves a built-in cluster ID to its module.

module_for_name(cluster_name)

@spec module_for_name(atom()) :: module() | nil

Resolves a built-in cluster name to its module.

revision(version)

(macro)