device

Provides device management and control utilities for Total Control scripting system.
Allows access to connected Android devices, querying device properties, and performing operations
such as selection, filtering, and batch execution. This module supports both object-oriented
(Device class) and utility-style APIs (getDevice, getDevices, etc.).

Features

  • Get the main or all connected Android devices
  • Filter devices by name, group, tag, serial number, or selection state
  • Access device properties like name, width, height, etc.
  • Handle collections of devices using DeviceArray and output wrappers

Usage Example

// Example 1:
var { Device, getDevices, getDevice } = require("sigma/device");

var mainDevice = getDevice();
if (mainDevice) {
    print("Main device name: " + mainDevice.name);
}

var selectedDevices = getDevices();
selectedDevices.forEach(d => print(d.name));

// Example 2: Get main device and read common properties
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    // If the device has no active network connection, this property will return `null`.
    var ip = sigmaDevice.IP;
    print("Device IP: " + ip);

    var dpi = sigmaDevice.DPI;
    print("Device DPI: " + dpi);

    var imei = sigmaDevice.IMEI;
    print("Device IMEI: " + imei);

    var sn = sigmaDevice.SN;
    print("Device SN: " + sn);

    var width = sigmaDevice.width;
    print("Device width: " + width);

    var height = sigmaDevice.height;
    print("Device height: " + height);

    var androidVersion = sigmaDevice.androidVersionRelease;
    print("Device Android Version: " + androidVersion);

    var sdkInt = sigmaDevice.androidVersionSdkInt;
    print("Device SDK Version: " + sdkInt);

    var brand = sigmaDevice.manufacturer;
    print("Device Manufacturer: " + brand);

    var model = sigmaDevice.model;
    print("Device Model: " + model);

    var no = sigmaDevice.no;
    print("Device No: " + no);

    var battery = sigmaDevice.battery;
    print("Device Battery: " + battery);

    var name = sigmaDevice.name;
    print("Device Name: " + name);
} else {
    print("Failed to get sigmaDevice object: " + lastError());
}

// Expected Output:
Device IP: 10.0.2.12
Device DPI: 320
Device IMEI: 867065021807297
Device SN: 7N2SQL154X038444
Device width: 720
Device height: 1280
Device androidVersionRelease: 5.1.1
Device androidVersionSdkInt: 22
Device manufacturer: HUAWEI
Device model: HUAWEI P7-L07
Device no: 0
Device battery: 100
Device name: Pioneer-K88L

connectAll()

Automatic connection device. A collection of device objects can manipulate device properties and control devices.

Example
var { Device } = require('sigma/device');
var sigmaDevice = Device.connectAll();
if (sigmaDevice != null) {
    print("Returns a collection of device objects: " + sigmaDevice);
} else {
    print("Failed to get the device object");
}

// If it executes successfully, it will return:
Returns a collection of device objects: device@779014370,device@230441652

getAll()

Get all devices.

Example
var { Device } = require('sigma/device');
var sigmaDevices = Device.getAll();
print(sigmaDevices)
// If it executes successfully, it will return:
device@159674573,device@46881454

getMain()

Get the main device object. Device objects can manipulate device properties and control devices.

Example
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (!sigmaDevice) {
    print("No device found.");
} else {
    const deviceName = device.getName();
    print("The device name is:" + deviceName);
}

getSelected()

Get all selected devices.

Example
var { Device } = require('sigma/device');
var sigmaDevices = Device.getSelected();
print(sigmaDevices)
// If it executes successfully, it will return:
device@159674573,device@46881454

searchObject(type, valueopt)

Get the device object by device name. Gets a collection of objects for all connected devices. Gets a collection of objects for all devices in the group based on the given group name. A collection of device objects can manipulate device properties and control devices. we encapsulate the obtained multi-device object as deviceArray, and more operations can be performed by calling the deviceArray method.

Example
// Example 1
var { Device } = require('sigma/device');
var sigmaDevice = Device.searchObject("HUAWEI-MSM8909");
if (!sigmaDevice) {
 print("The device was not found");
} else {
var devicemodel = device.model;
print("The device model is:" + devicemodel);
//If it executes successfully, it will return:
The device model is:MSM8909

// Example 2
var { Device } = require('sigma/device');
var sigmaDevices = Device.searchObject(tcConst.DevAll);
if (sigmaDevices != null) {
    print("Object collection of currently connected devices:" + devices);
} else {
    print("No device found.");
}
// If it executes successfully, it will return:
Object collection of currently connected devices:device@779014370,device@33254183,device@230441652

// Example 3
var { Device } = require('sigma/device');
var sigmaDevice = Device.searchObject(tcConst.DevGroup, "Group 1");
if (sigmaDevice != null) {
    print("Returns device objects: " + device);
} else {
    print("No device found.");
}

// If it executes successfully, it will return:
Returns device objects: device@33254183,device@230441652

// Example 4
var { Device } = require('sigma/device');
var sigmaDevice = Device.searchObject(tcConst.DevSerial,"YP5LAUGYUSDE9TMV");
if (!sigmaDevice) {
    print(lastError());
} else {
    var deviceName = sigmaDevice.getName();
    sigmaDevice.click(100, 200);
}

// Example 5
var { Device } = require('sigma/device');
var runAppName="com.huawei.camera"
var sigmaDevice = Device.searchObject(tcConst.DevSelectOne);
if (!sigmaDevice) {
    print("No device found.");
} else {
    sigmaDevice.runApp(runAppName);
}

// Example 6
var { Device } = require('sigma/device');
var runAppName="com.huawei.camera"
var sigmaDevices = Device.searchObject(tcConst.DevSelectMult);
if (!sigmaDevices) {
    print("No device found.");
} else {
    sigmaDevices.runApp(runAppName);
}

// Example 7
var { Device } = require('sigma/device');
var runAppName="com.huawei.camera"
var sigmaDevices = Device.searchObject(tcConst.DevSelectGroup);
if (!sigmaDevices) {
    print("No device found.");
} else {
    sigmaDevices.runApp(runAppName);
}

// Example 8
var { Device } = require('sigma/device');
var runAppName="com.huawei.camera"
var sigmaDevices = Device.searchObject(tcConst.DevTag, "a");
if (!sigmaDevices) {
    print("No device found.");
} else {
    sigmaDevices.runApp(runAppName);
}
Parameters:
String type

Device name or A constant value "tcConst.DevAll" or A constant value "tcConst.DevGroup"

String value <optional>

Group name

Supports:

  1. Device.searchObject(DeviceName)
  2. Device.searchObject(tcConst.DevAll)
  3. Device.searchObject(tcConst.DevGroup, GroupName)
  4. Device.searchObject(tcConst.DevSerial,Serial)
  5. Device.searchObject(tcConst.DevSelectOne)
  6. Device.searchObject(tcConst.DevSelectMult)
  7. Device.searchObject(tcConst.DevSelectGroup)
  8. Device.searchObject(tcConst.DevTag, TagName)

(inner) getAllDevices() → {Array}

Retrieve all currently connected device objects and obtain an array containing all devices.
If all device objects are successfully obtained, an array object will be returned where all devices point to the phone.

Example
var { getAllDevices } = require("sigma/device");
var sigmaDevices = getAllDevices();
print(sigmaDevices)

// If it executes successfully, it will return:
device@159674573,device@46881454
Returns:
Array

The array of all connected device objects

(inner) getDevice() → {Object}

Retrieve the current main control device object, which can be used to manipulate the device's properties and controls.
If the current master device object is successfully obtained, an object will be returned, where all devices refer to mobile phones.

Example
var { getDevice } = require("sigma/device");
var sigmaDevice = getDevice()
if (!sigmaDevice) {
    print("No device found.");
} else {
    var deviceName = sigmaDevice.getName();
    print("The device name is:" + deviceName);
}

// If it executes successfully, it will return:
The device name is:HUAWEI-MSM8909
Returns:
Object

the main device object

(inner) getDevices() → {Array}

Get all selected devices

Example
var { getDevices } = require("sigma/device");
var sigmaDevices = getDevices();
print(sigmaDevices)

// If it executes successfully, it will return:
device@159674573,device@46881454
Returns:
Array

The array of selected device objects

(inner) searchGroup(name) → {DeviceArray|null}

Search for devices inside a specific group. This returns multiple devices if the group
contains more than one device. Internally calls Device.searchObject(tcConst.DevGroup).

Example
var { searchGroup } = require("sigma/device");

var sigmaDevices = searchGroup("Group 1");
if (sigmaDevices) {
    print("Devices in group:");
    sigmaDevices.forEach(d => print(" - " + d.name));
} else {
    print("No devices found in this group: " + lastError());
}
Parameters:
string name

Group name to search for.

Returns:
DeviceArray | null

A DeviceArray of devices in the group, or null if the group is empty.

(inner) searchName(name) → {Device|null}

Search for a device by its name. This method internally calls Device.searchObject
and returns a single Device instance if matched.

Example
var { searchName } = require("sigma/device");

var sigmaDevice = searchName("HUAWEI-MSM8909");
if (sigmaDevice) {
    print("Device found: " + sigmaDevice.name);
    print("Model: " + sigmaDevice.model);
    print("Resolution: " + sigmaDevice.width + "x" + sigmaDevice.height);
} else {
    print("Device not found: " + lastError());
}
Parameters:
string name

The device name to search for.

Returns:
Device | null

A Device object if found, or null if no device matches the name.

(inner) searchSerial(serial) → {Device|null}

Search for a device by its serial number (SN). This method internally calls
Device.searchObject(tcConst.DevSerial, serial) and returns a single Device.

Example
var { searchSerial } = require("sigma/device");

var sn = "YP5LAUGYUSDE9TMV";
var sigmaDevice = searchSerial(sn);
if (sigmaDevice) {
    print("Device found by SN:");
    print("Name: " + sigmaDevice.name);
    print("Model: " + sigmaDevice.model);
    print("SN: " + sigmaDevice.SN);

    // Example: tap on the screen at (100, 200)
    sigmaDevice.click(100, 200);
} else {
    print("Device not found by SN: " + lastError());
}
Parameters:
string serial

The device serial number (SN).

Returns:
Device | null

A Device object if found, or null if no device matches the serial.

(inner) searchTag(name) → {DeviceArray|null}

Search for devices by tag. This method internally calls
Device.searchObject(tcConst.DevTag, TagName). Returns DeviceArray if multiple devices match.

Example
var { searchTag } = require("sigma/device");

var sigmaDevices = searchTag("CameraTest");
if (sigmaDevices) {
    print("Devices tagged with 'CameraTest':");
    sigmaDevices.forEach(d => print(" - " + d.name + " (" + d.IP + ")"));
} else {
    print("No devices found with tag: " + lastError());
}
Parameters:
string name

The tag associated with the device(s).

Returns:
DeviceArray | null

A DeviceArray of tagged devices, or null if none match.

(inner) selectGroup() → {DeviceArray|null}

After running the script, a device group selection window pops up, get a collection of objects for
all devices in the group based on a selected device group.A collection of device objects can
manipulate device properties and control devices.The result is always a DeviceArray.
Internally calls Device.searchObject(sigmaConst.DevSelectGroup).

Example
var { selectGroup } = require("sigma/device");

var sigmaDevices = selectGroup();
if (sigmaDevices) {
    print("Devices in the selected group:");
    sigmaDevices.forEach(d => print(" - " + d.name));
} else {
    print("No devices found in selected group: " + lastError());
}
Returns:
DeviceArray | null

A DeviceArray of devices from the selected group, or null if none found.

(inner) selectMultiple() → {DeviceArray|null}

After running the script, a device selection box will pop up, get a collection of device objects
based on multiple devices selected. A collection of device objects can manipulate device properties
and control devices. Internally calls Device.searchObject(tcConst.DevSelectMult).

Example
var { selectMultiple } = require("sigma/device");

var sigmaDevices = selectMultiple();
if (sigmaDevices) {
    print("Selected devices:");
    sigmaDevices.forEach(d => print(" - " + d.name));

    // Example: run the same command on all devices
    sigmaDevices.runApp("com.huawei.camera");
} else {
    print("No multiple-device selection available: " + lastError());
}
Returns:
DeviceArray | null

A collection of selected devices, or null if no devices are selected.

(inner) selectOne() → {Device|null}

After running the script, a device selection box will pop up, and the device object is obtained
according to the selected device. A collection of device objects can manipulate device properties
and control devices. The returned value is always a single Device object or null.
Internally calls Device.searchObject(tcConst.DevSelectOne).

Example
var { selectOne } = require("sigma/device");

var sigmaDevice = selectOne();
if (sigmaDevice) {
    print("Selected device: " + sigmaDevice.name);
    sigmaDevice.runApp("com.android.settings");
} else {
    print("No device selected: " + lastError());
}
Returns:
Device | null

A single selected device, or null if selection fails.