Device Management
Overview
This section contains all components and utilities for Device Management.
Components
| Item | Type | Description |
|---|---|---|
| this.device (DeviceAPI) | Class | Device management API for monitoring and responding to device state changes. |
| DeviceChanges | Interface | Device update event data containing control value changes. |
| DeviceConnectionCallback | Unknown | Callback function type for device connection events. |
| DeviceInfo | Interface | Information about a connected device. |
| DeviceUpdateCallback | Unknown | Callback 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
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
| Method | Parameters | Description |
|---|---|---|
getConnected() | - | Gets a list of all currently connected devices.. |
isConnected() | - | Checks if any device is currently connected.. |
onConnect() | callback: DeviceConnectionCallback | Registers a callback function to be called when a device connects. |
onDisconnect() | callback: DeviceConnectionCallback | Registers a callback function to be called when a device disconnects. |
onUpdate() | callback: DeviceUpdateCallback | Registers a callback function to be called when device values are updated. |
triggerConnect() | device: DeviceInfo | Internal method to trigger connect callbacks. |
triggerDisconnect() | device: DeviceInfo | Internal method to trigger disconnect callbacks. |
triggerUpdate() | data: DeviceChanges | Internal method to trigger update callbacks. |
getConnected()
getConnected(): PromiseGets a list of all currently connected devices.
Returns:
Promise - Promise that resolves to an array of connected devices
Example:
// 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()
isConnected(): PromiseChecks if any device is currently connected.
Returns:
Promise - Promise that resolves to true if at least one device is connected, false otherwise
Example:
// 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()
onConnect(callback: DeviceConnectionCallback): voidRegisters a callback function to be called when a device connects.
Multiple callbacks can be registered and will all be called in order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
callback | DeviceConnectionCallback | Yes | Function to call when a device connects |
Example:
// 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()
onDisconnect(callback: DeviceConnectionCallback): voidRegisters a callback function to be called when a device disconnects.
Multiple callbacks can be registered and will all be called in order.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
callback | DeviceConnectionCallback | Yes | Function to call when a device disconnects |
Example:
// 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()
onUpdate(callback: DeviceUpdateCallback): voidRegisters 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:
| Name | Type | Required | Description |
|---|---|---|---|
callback | DeviceUpdateCallback | Yes | Function to call when device values change |
Example:
// 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()
triggerConnect(device: DeviceInfo): PromiseInternal method to trigger connect callbacks. Called by the APIClient when a device_connected event is received.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
device | DeviceInfo | Yes | No description |
triggerDisconnect()
triggerDisconnect(device: DeviceInfo): PromiseInternal method to trigger disconnect callbacks. Called by the APIClient when a device_disconnected event is received.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
device | DeviceInfo | Yes | No description |
triggerUpdate()
triggerUpdate(data: DeviceChanges): PromiseInternal method to trigger update callbacks. Called by the APIClient when a device_update event is received.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
data | DeviceChanges | Yes | No 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 compareoldValueandnewValueto 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.