Data structure describing a Z-Wave command, including how to create, encode, and decode it.
Summary
Command Specs
Get the handler and options for a command.
Create a new command spec.
Create a new command spec.
Validate a command spec.
Validates a list of parameter specs.
Commands
Create a command struct from the command spec and parameters.
Validate a command's parameters according to the command spec.
Types
@type report_matcher() :: (get :: Grizzly.ZWave.Command.t(), report :: Grizzly.ZWave.Command.t() -> boolean())
@type t() :: %Grizzly.ZWave.CommandSpec{ command_byte: byte(), command_class: atom(), decode_fun: {module(), atom()}, default_params: keyword(), encode_fun: {module(), atom()}, handler: {module(), keyword()}, module: module(), name: atom(), params: [{atom(), Grizzly.ZWave.ParamSpec.t()}], report: atom() | nil, report_matcher_fun: {module(), atom()} | nil, supports_supervision?: boolean(), validate_fun: {module(), atom()} | (keyword() -> {:ok, keyword()} | {:error, any()}) | nil }
:name(atom/0) - Required. The command's name as an atom (should be globally unique).:command_class(Grizzly.ZWave.CommandClasses.command_class/0) - Required. The command class this command belongs to.:module(atom/0) - Required. The module implementing this command's encoding and decoding functions.:command_byte- Required. The command identifier.:encode_fun- Required. A function or{module, function}tuple used to encode the command's parameters into a binary. Only 1-arity functions are currently supported.:decode_fun- Required. A function or{module, function}tuple used to decode the command's parameters from binary to a keyword list (the reverse of theencode_fun).If the function is of arity 1, the first argument will be the binary to decode. If arity 2, the command spec will be inserted as the first argument.
:report_matcher_fun- A 2-arity function or{module, function}tuple used to match a report command to a get command. The first argument will be the get command and the second argument will be the report command to match. The function should returntrueif the report matches the get.:report(atom/0) - The name of the report command associated with this command, if any. For get commands, this will default to the command name with the trailing_getreplaced with_report. To override this behavior, explicitly set this field to nil.A special value of
:anymay be used to indicate that any report command can satisfy this particular get command. Otherwise, this should be the name of a registered report command.:handler(tuple ofatom/0,keyword/0values) - A{module, options}tuple indicating the request handler that should be used to handle completion of this command when sent via aGrizzly.Request. Normally, this will default to{AckResponse, []}. However, if the:reportoption is specified but:handleris not, the default becomes{WaitReport, complete_report: report}.:supports_supervision?(boolean/0) - Whether this command supports Z-Wave Supervision. Defaults tofalsefor commands whose names end with_get. Defaults totruefor commands whose names end with_setor_report. Defaults tofalsefor commands namednetwork_management_*, as most of these are only supported by Z/IP Gateway. The default value istrue.:validate_fun- A{module, function}tuple indicating a function that validates the command parameters. The function should return{:ok, params}if the parameters are valid or have been updated, or{:error, reason}if the parameters are invalid.:params- The default value is[].:default_params(keyword/0) - A keyword list of default parameters for the command. These parameters will be merged with any parameters passed tocreate_command/2before validation. The default value is[].
Command Specs
Get the handler and options for a command.
Create a new command spec.
Create a new command spec.
Validate a command spec.
@spec validate_param_list([{atom(), Grizzly.ZWave.ParamSpec.t()}]) :: {:ok, [{atom(), Grizzly.ZWave.ParamSpec.t()}]} | {:error, String.t()}
Validates a list of parameter specs.
Examples
iex> params = [
...> param1: %Grizzly.ZWave.ParamSpec{name: :param1, type: :uint, size: 8},
...> param2: %Grizzly.ZWave.ParamSpec{name: :param2, type: :int, size: 16}
...> ]
iex> Grizzly.ZWave.CommandSpec.validate_param_list(params)
{:ok, params}
iex> params = [
...> param1: %Grizzly.ZWave.ParamSpec{name: :param1, type: :uint, size: 7},
...> param2: %Grizzly.ZWave.ParamSpec{name: :param2, type: :int, size: 8}
...> ]
iex> Grizzly.ZWave.CommandSpec.validate_param_list(params)
{:error, "Total size of all non-variable parameters must be a multiple of 8 bits"}
iex> params = [
...> param1: %Grizzly.ZWave.ParamSpec{name: :param1, type: :uint, size: :variable},
...> param2: %Grizzly.ZWave.ParamSpec{name: :param2, type: :int, size: 16}
...> ]
iex> Grizzly.ZWave.CommandSpec.validate_param_list(params)
{:error, "Variable-length parameter without length specifier must be last"}