Skip to content

Device Management ​

Overview ​

This section contains all components and utilities for Device Management.

Components ​

ItemTypeDescription
this.device (DeviceAPI)ClassDevice management API for monitoring and responding to device state changes.
DeviceChangesInterfaceDevice update event data containing control value changes.
DeviceConnectionCallbackUnknownCallback function type for device connection events.
DeviceInfoInterfaceInformation about a connected device.
DeviceUpdateCallbackUnknownCallback function type for device update events.

this.device (DeviceAPI) ​

Device management API for monitoring and responding to device state changes.

Access this API via this.device in your plugin class.

Example ​

typescript
export default class MyPlugin extends Plugin {
  async onLoad() {
    // Get currently connected devices
    const devices = await this.device.getConnected();
    console.log('Connected devices:', devices);
    
    // Listen for device connections
    this.device.onConnect((device) => {
      console.log('Device connected:', device.name);
      this.ui.showToast({
        message: `${device.name} connected!`,
        type: 'success'
      });
    });
    
    // Listen for device disconnections
    this.device.onDisconnect((device) => {
      console.log('Device disconnected:', device.name);
      this.ui.showToast({
        message: `${device.name} disconnected`,
        type: 'warning'
      });
    });
    
    // Listen for device value updates
    this.device.onUpdate((data) => {
      data.changes.forEach(change => {
        console.log(`Control ${change.index}: ${change.oldValue} → ${change.newValue}`);
      });
    });
  }
}

Properties ​

  • rgb (RGBController): RGB controller for managing device lighting effects.

Control the 8 RGB LEDs on the Decker device with various effects, colors, brightness levels, and animation speeds.

Methods ​

MethodParametersDescription
getConnected()-Gets a list of all currently connected devices..
isConnected()-Checks if any device is currently connected..
onConnect()callback: DeviceConnectionCallbackRegisters a callback function to be called when a device connects.
onDisconnect()callback: DeviceConnectionCallbackRegisters a callback function to be called when a device disconnects.
onUpdate()callback: DeviceUpdateCallbackRegisters a callback function to be called when device values are updated.
triggerConnect()device: DeviceInfoInternal method to trigger connect callbacks.
triggerDisconnect()device: DeviceInfoInternal method to trigger disconnect callbacks.
triggerUpdate()data: DeviceChangesInternal method to trigger update callbacks.

getConnected() ​

typescript
getConnected(): Promise

Gets a list of all currently connected devices.

Returns:

Promise - Promise that resolves to an array of connected devices

Example:

typescript
// Check if any devices are connected
const devices = await this.device.getConnected();

if (devices.length > 0) {
  console.log(`${devices.length} device(s) connected`);
  devices.forEach(device => {
    console.log(`- ${device.name} on ${device.port}`);
  });
} else {
  console.log('No devices connected');
}

isConnected() ​

typescript
isConnected(): Promise

Checks if any device is currently connected.

Returns:

Promise - Promise that resolves to true if at least one device is connected, false otherwise

Example:

typescript
// Check if device is connected before performing operations
if (await this.device.isConnected()) {
  await this.device.rgb.setEffect('rainbow', 75, 100, '#FFFFFF');
} else {
  console.log('No device connected');
}

onConnect() ​

typescript
onConnect(callback: DeviceConnectionCallback): void

Registers a callback function to be called when a device connects.

Multiple callbacks can be registered and will all be called in order.

Parameters:

NameTypeRequiredDescription
callbackDeviceConnectionCallbackYesFunction to call when a device connects

Example:

typescript
// Simple connection handler
this.device.onConnect((device) => {
  console.log('Device connected:', device.name);
});

// Connection handler with async operations
this.device.onConnect(async (device) => {
  await this.ui.showToast({
    message: `${device.name} is now connected`,
    type: 'success'
  });
  
  // Initialize device-specific features
  await this.initializeDeviceFeatures(device);
});

onDisconnect() ​

typescript
onDisconnect(callback: DeviceConnectionCallback): void

Registers a callback function to be called when a device disconnects.

Multiple callbacks can be registered and will all be called in order.

Parameters:

NameTypeRequiredDescription
callbackDeviceConnectionCallbackYesFunction to call when a device disconnects

Example:

typescript
// Simple disconnection handler
this.device.onDisconnect((device) => {
  console.log('Device disconnected:', device.name);
});

// Disconnection handler with cleanup
this.device.onDisconnect(async (device) => {
  await this.ui.showToast({
    message: `${device.name} has been disconnected`,
    type: 'warning'
  });
  
  // Clean up device-specific resources
  this.cleanupDeviceFeatures(device);
});

onUpdate() ​

typescript
onUpdate(callback: DeviceUpdateCallback): void

Registers a callback function to be called when device values are updated.

This is triggered when sliders, knobs, buttons, or other controls on the device change. Multiple callbacks can be registered and will all be called in order.

Parameters:

NameTypeRequiredDescription
callbackDeviceUpdateCallbackYesFunction to call when device values change

Example:

typescript
// Handle all device value updates
this.device.onUpdate((data) => {
  console.log('Device updated:', data);
  
  // Process each change
  data.changes.forEach(change => {
    console.log(`Control ${change.index}: ${change.oldValue} → ${change.newValue}`);
  });
});

// Handle specific control changes
this.device.onUpdate((data) => {
  data.changes.forEach(change => {
    // Volume control (index 0)
    if (change.index === 0) {
      console.log(`Volume changed to ${change.newValue}%`);
      if (change.newValue > 80) {
        this.ui.showToast({
          message: 'Volume is very high!',
          type: 'warning'
        });
      }
    }
  });
});

triggerConnect() ​

typescript
triggerConnect(device: DeviceInfo): Promise

Internal method to trigger connect callbacks. Called by the APIClient when a device_connected event is received.

Parameters:

NameTypeRequiredDescription
deviceDeviceInfoYesNo description

triggerDisconnect() ​

typescript
triggerDisconnect(device: DeviceInfo): Promise

Internal method to trigger disconnect callbacks. Called by the APIClient when a device_disconnected event is received.

Parameters:

NameTypeRequiredDescription
deviceDeviceInfoYesNo description

triggerUpdate() ​

typescript
triggerUpdate(data: DeviceChanges): Promise

Internal method to trigger update callbacks. Called by the APIClient when a device_update event is received.

Parameters:

NameTypeRequiredDescription
dataDeviceChangesYesNo description

DeviceChanges ​

Device update event data containing control value changes.

Properties ​

  • changes ({ index: number; oldValue: number; newValue: number }[]): One entry per device control, with values from 0 to 100. Every control is included on each update, so compare oldValue and newValue to find the ones that moved.
  • sliders (number[]): Current value (0-100) of every device control, indexed by channel.

DeviceConnectionCallback ​

Callback function type for device connection events.


DeviceInfo ​

Information about a connected device.

Properties ​

  • connected_at (string): ISO timestamp of when the device connected
  • name (string): Device name (e.g., "Decker", "Dot X")
  • port (string): Port or connection identifier
  • state ("connected" | "disconnected"): Connection state

DeviceUpdateCallback ​

Callback function type for device update events.