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
DeviceArrayand 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
Functions
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:
|
(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 |
| Object |
the main device object |
| Array |
The array of selected device objects |
| string | name |
Group name to search for. |
Returns:
| DeviceArray | null |
A DeviceArray of devices in the group, or null if the group is empty. |
| string | name |
The device name to search for. |
Returns:
| Device | null |
A Device object if found, or null if no device matches the name. |
| string | serial |
The device serial number (SN). |
Returns:
| Device | null |
A Device object if found, or null if no device matches the serial. |
| string | name |
The tag associated with the device(s). |
Returns:
| DeviceArray | null |
A DeviceArray of tagged devices, or null if none match. |
| DeviceArray | null |
A DeviceArray of devices from the selected group, or null if none found. |
| DeviceArray | null |
A collection of selected devices, or null if no devices are selected. |
| Device | null |
A single selected device, or null if selection fails. |