View Source Grizzly.ZWave.Command behaviour (grizzly v8.6.6)

Data struct and behaviour for working with Z-Wave commands

Summary

Callbacks

Decode the binary string of command params

Encode the command parameters

Encode the command parameters with encoding options

Make a new Command.t() from the params provided

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.

Functions

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

Types

delay_seconds()

@type delay_seconds() :: non_neg_integer()

params()

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

t()

@type t() :: %Grizzly.ZWave.Command{
  command_byte: byte() | nil,
  command_class: Grizzly.ZWave.CommandClass.t(),
  impl: module(),
  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
  • :impl - the module that implements the Command behaviour

Callbacks

decode_params(binary)

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

Decode the binary string of command params

encode_params(t)

@callback encode_params(t()) :: binary()

Encode the command parameters

encode_params(t, opts)

(optional)
@callback encode_params(t(), opts :: keyword()) :: binary()

Encode the command parameters with encoding options

The encoding options help pass extra context to how the parameters for the command should be encoded.

This is an optional callback.

new(params)

@callback new(params :: keyword()) :: {:ok, t()} | {:error, reason :: any()}

Make a new Command.t() from the params provided

Param validation should take place here.

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.

Functions

encode_params(command)

@spec encode_params(t()) :: binary()

has_param?(command, param)

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

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