Grizzly.ZWave.Command behaviour (grizzly v9.1.0)

Copy Markdown View Source

Data struct and behaviour for working with Z-Wave commands

Summary

Types

Command-specific payload parameters.

t()

Command struct

Callbacks

Encode the command parameters

Encode the command parameters

Returns true if the report is a good match for the get command. This is useful for commands like Version Command Class Get, which can be sent in rapid succession during a device interview, which can lead to reports getting matched back to the wrong get.

Validate the command's parameters.

Functions

Returns true if the param exists in the command's parameter list.

Create a command struct from the given spec and parameters.

Get the command param value out the params list

Just like param/3 but will raise if the the param is not in the param list

Put the param value into the params list, updating pervious value if there is one

Encode the Command.t() into it's binary representation

Validate a command's parameters according to the command spec.

Types

params()

@type params() :: Keyword.t()

Command-specific payload parameters.

t()

@type t() :: %Grizzly.ZWave.Command{
  command_byte: byte() | nil,
  command_class: atom(),
  name: atom(),
  params: params()
}

Command struct

  • :name - the name of the command
  • :command_class - the command class module for the command
  • :command_byte - the byte representation of the command
  • :params - the parameters for the command as outlined by the Z-Wave specification
  • :spec - the command spec as defined in Grizzly.ZWave.Commands

Callbacks

decode_params(t, binary)

@callback decode_params(Grizzly.ZWave.CommandSpec.t(), binary()) ::
  {:ok, keyword()} | {:error, Grizzly.ZWave.DecodeError.t()}

Encode the command parameters

encode_params(t, t)

@callback encode_params(Grizzly.ZWave.CommandSpec.t(), t()) :: binary()

Encode the command parameters

report_matches_get?(get, report)

(optional)
@callback report_matches_get?(get :: t(), report :: t()) :: boolean()

Returns true if the report is a good match for the get command. This is useful for commands like Version Command Class Get, which can be sent in rapid succession during a device interview, which can lead to reports getting matched back to the wrong get.

This is an optional callback. If not implemented, command handlers will assume true.

validate_params(t, params)

(optional)
@callback validate_params(Grizzly.ZWave.CommandSpec.t(), params :: keyword()) ::
  {:ok, validated_params :: keyword()} | {:error, reason :: any()}

Validate the command's parameters.

The callback should return {:ok, validated_params} if the parameters are valid, or {:error, reason} if they are not. Implementers may modify the parameters during validation (e.g., setting defaults).

Functions

has_param?(command, param)

@spec has_param?(t(), atom()) :: boolean()

Returns true if the param exists in the command's parameter list.

new(spec, params \\ [])

@spec new(Grizzly.ZWave.CommandSpec.t(), params :: keyword()) ::
  {:ok, t()} | {:error, :unknown_command}

Create a command struct from the given spec and parameters.

param(command, param, default \\ nil)

@spec param(t(), atom(), term()) :: term() | nil

Get the command param value out the params list

param!(command, param)

@spec param!(t(), atom()) :: term() | no_return()

Just like param/3 but will raise if the the param is not in the param list

put_param(command, param, new_value)

@spec put_param(t(), atom(), any()) :: t()

Put the param value into the params list, updating pervious value if there is one

to_binary(command)

@spec to_binary(t()) :: binary()

Encode the Command.t() into it's binary representation

validate_params(spec, params)

Validate a command's parameters according to the command spec.