View Source Grizzly.VirtualDevices (grizzly v8.6.6)

Virtual devices

Virtual devices are in-memory devices that act like a Z-Wave device

Summary

Types

Options for adding a virtual devices

Id for a virtual device

Options for removing virtual devices

Functions

Add a new virtual device to the virtual device network

Same as add_device/3 but raises an ArgumentError if a device with the requested id is already registered.

Broadcast a command to the rest of the Z-Wave network

List the nodes in the virtual devices network

Remove a device from the virtual device network

Send a Z-Wave command to the virtual device

Get the pid for the device id

Types

add_opt()

@type add_opt() ::
  {:inclusion_handler, Grizzly.handler()}
  | Grizzly.VirtualDevices.Device.device_opt()

Options for adding a virtual devices

  • :inclusion_handler - if an inclusion handler is provider via the add options it will override the initial inclusion handle argument to the network server if one was provided only for that one call to add_device/2.

You may also include other device options that will passed to your callback functions for implementation specific support.

device_entry()

@type device_entry() :: %{
  device_impl: Grizzly.VirtualDevices.Device.t(),
  device_class: Grizzly.ZWave.DeviceClass.t(),
  device_opts: [Grizzly.VirtualDevices.Device.device_opt()],
  id: id(),
  pid: pid()
}

id()

@type id() :: {:virtual, integer()}

Id for a virtual device

remove_opt()

@type remove_opt() :: {:inclusion_handler, Grizzly.handler()}

Options for removing virtual devices

  • :inclusion_handler - if an inclusion handler is provider via the add options it will override the initial inclusion handle argument to the network server if one was provided only for that one call to remove_device/2.

Functions

add_device(device_id, device_impl, opts \\ [])

@spec add_device(id(), Grizzly.VirtualDevices.Device.t(), [add_opt()]) ::
  {:ok, id()} | {:error, {:already_registered, device_entry()}}

Add a new virtual device to the virtual device network

To add a virtual device you must supply a module that implements the Grizzly.VirtualDevices.Device behaviour.

If the device takes any options you can pass a tuple of {device, opts}.

add_device!(device_id, device_impl, opts \\ [])

@spec add_device!(id(), Grizzly.VirtualDevices.Device.t(), [add_opt()]) :: id()

Same as add_device/3 but raises an ArgumentError if a device with the requested id is already registered.

broadcast_command(device_id, command)

@spec broadcast_command(id(), Grizzly.ZWave.Command.t()) :: :ok

Broadcast a command to the rest of the Z-Wave network

list_nodes()

@spec list_nodes() :: [id()]

List the nodes in the virtual devices network

remove_device(device_id, opts \\ [])

@spec remove_device(id(), [remove_opt()]) :: :ok

Remove a device from the virtual device network

send_command(device_id, node_info_get)

@spec send_command(id(), Grizzly.ZWave.Command.t()) ::
  {:ok, Grizzly.Report.t()} | {:error, :device_not_found | Grizzly.Report.t()}

Send a Z-Wave command to the virtual device

whereis(device_id)

@spec whereis(id()) :: pid() | nil

Get the pid for the device id

This is useful for when you device is processed-based and you need to send messages to it.