Search documentation of grizzly

# View Source Grizzly.VirtualDevices.Device behaviour (grizzly v7.4.2)

Behaviour for implementing virtual device specifics

# Summary

## Types

device_opt()

Optional device options that are passed with calling implemented callbacks

t()

A module that implements this behaviour

## Callbacks

device_spec(list)

Return the device specification

handle_command(t, list)

Handle a Z-Wave command

set_device_id(pid, id)

Set the virtual device's id once added to the (virtual) Z-Wave network.

# Types

Link to this type

# device_opt()

View Source

    @type device_opt() :: {atom(), term()}

Optional device options that are passed with calling implemented callbacks

This can be whatever extra information the consumer might need the device to know about when executing the callback function.

Link to this type

# t()

View Source

    @type t() :: module()

A module that implements this behaviour

# Callbacks

Link to this callback

# device_spec(list)

View Source

    @callback device_spec([device_opt()]) :: Grizzly.ZWave.DeviceClass.t()

Return the device specification

Link to this callback

# handle_command(t, list)

View Source

    @callback handle_command(Grizzly.ZWave.Command.t(), [device_opt()]) ::
      :ok
      | {:ok, Grizzly.ZWave.Command.t()}
      | {:notify, Grizzly.ZWave.Command.t()}
      | {:error, :timeout}

Handle a Z-Wave command

When handling a command you can reply, notify, or do nothing.

In Z-Wave if your device does not understand the command sent it ignores the command. For this case you'd return `{:error, :timeout}`.

When a command is received and your device supports the command and the command's parameters, you either respond with `:ok` or `{:ok, Command.t()}`. Normally, when you receive a "set" command you will want to response with `:ok`. When you receive a "get" command you will want to response the report command like `{:ok, Command.t()}`, where the `Command.t()` is whatever command report you want to send to the caller.

Often times, if your device reports changes that have been made due to handling a command, you can return `{:notify, Command.t()}`.

Link to this callback

# set_device_id(pid, id)

View Source

    @callback set_device_id(pid(), Grizzly.VirtualDevices.id()) :: :ok

Set the virtual device's id once added to the (virtual) Z-Wave network.