Skip to content

Command Structure

Logan Savage edited this page Jun 13, 2026 · 3 revisions

Command Structure

This library is designed around a builder and a per-device syntax.

Builder Syntax

The builder syntax contains two sections for a command:

  1. Filters, which sequentially filter down the devices shown
  2. Actions, which are a sequence of actions to perform on the devices that pass through every filter

With this, the structure of a command is:

err := controller.Devices().
  <filterFunctions>.
  <actionFunctions>.
  Exec()

Example

err = controller.Devices().
	TypeIs(veego.DeviceLight).   // Filter function
	NameMatches("^Living Room"). // Filter function
	Off().                       // Action function
	Exec()

Per-Device Syntax

Using the per-device syntax involves getting devices from the filter section of the builder syntax, followed by a .Query() call to get a slice of Devices. Each device can individually be checked for capability statuses and be acted upon similar to the builder syntax.

Example

// Get every light device as a []veego.Device
devs := controller.Devices().
	TypeIs(veego.DeviceLight).
	Query()

// Guard for ensuring at least one device was found
if len(devs) == 0 {
	log.Fatal("0 devices found.")
}

// Turn off the first returned device
devs[0].Off()

Clone this wiki locally