SmartDevicesManager.batchAdd(configs: AddConfig[], options?: BatchAddOptions)

Requires:
@ray-js/panel-sdk≥1.16.0

Description

Add device instances to the multi-device manager in bulk. It first fetches device info in batch (a single network request), then initializes concurrently according to concurrency; partial failures are supported and the result distinguishes success and failure lists. Each device can configure interceptors and logConfig independently.

Parameters

ParameterTypeRequiredDescription
YesList of device configs
NoConfiguration options

Return Value

Type: Promise<BatchAddResult>
Result object containing success and failed; success is a map of successfully initialized device instances, failed is a list of devices that failed to initialize

Referenced Types

typeBatchAddResult
PropertyTypeDescription
successRecord<string, SmartDeviceModel>Mapping of successfully initialized device instances
failedFailedDeviceInfo[]List of devices that failed to initialize
typeInitDpStateInterceptor
export type InitDpStateInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = InitDpStateInterceptorParams
> = Interceptor<S, P, InitDpStateInterceptorParams>;
typeInitDevInfoInterceptor
export type InitDevInfoInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = {
    devInfo: GetSmartDeviceModelDevInfo<any>;
    action: InitDevInfoInterceptorAction;
  }
> = Interceptor<
  S,
  P,
  {
    devInfo: GetSmartDeviceModelDevInfo<any>;
    action: InitDevInfoInterceptorAction;
  }
>;
typeOnDpDataChangeInterceptor
export type OnDpDataChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DpDataChangeParams
> = Interceptor<S, P, DpDataChangeParams>;
typeOnDeviceOnlineStatusUpdateInterceptor
export type OnDeviceOnlineStatusUpdateInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DeviceOnlineStatusUpdateParams
> = Interceptor<S, P, DeviceOnlineStatusUpdateParams>;
typeOnDeviceInfoUpdatedInterceptor
export type OnDeviceInfoUpdatedInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DeviceInfoUpdatedParams
> = Interceptor<S, P, DeviceInfoUpdatedParams>;
typeOnNetworkStatusChangeInterceptor
export type OnNetworkStatusChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = NetworkStatusChangeParams
> = Interceptor<S, P, NetworkStatusChangeParams>;
typeOnBluetoothAdapterStateChangeInterceptor
export type OnBluetoothAdapterStateChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = BluetoothAdapterStatusChangeParams
> = Interceptor<S, P, BluetoothAdapterStatusChangeParams>;
typeInitDpStateInterceptorParams
PropertyTypeRequiredDescription
YesCurrent device DP state
YesNew device DP state
action"init" | "onDpDataChange" | "onDeviceInfoUpdated" | "dp-kit"YesInterceptor action
typeGetSmartDeviceModelDevInfo
PropertyTypeRequiredDescription
dpCodesobjectYes
dpsobjectYes
idCodesobjectYes
codeIdsobjectYes
schemaSYes
typeSmartDeviceModelAbilityContainer type for SmartDeviceModel abilities, used only for generic constraints and internal composition.
export type SmartDeviceModelAbility<A extends SmartDeviceAbility = SmartDeviceAbility> = {
  [abilityName: string]: A;
};
typePublishDpsOptionsUnderlying option type of publishDps, reused by the SDK’s internal request chain.
PropertyTypeRequiredDescription
No
typeDpValueDatapoint value type, which can be boolean, number, or string.
export type DpValue = boolean | number | string;
typeSendDpOptionDP send options. Can be used as the global default configuration for createDpKit, and can also be overridden in a single publishDps/action call. The global `sendDpOption` suits product-level defaults; options passed for a single send are suitable for temporarily overriding throttling, debouncing, protocol parsing, or optimistic update strategies. Note: requires the dp-kit interceptor.
PropertyTypeRequiredDescriptionSince
immediatebooleanNoWhether to trigger a state update immediately; requires the dp-kit interceptor-
NoWhether to ignore DP reports; default falsev1.11.0
NoWhether to sync dpData with cloud device properties; default falsev1.11.0
orderedbooleanNoWhether to send multiple DPs in the order of the object’s keys; requires the dp-kit interceptor; default false-
checkRepeatbooleanNoWhether to check for duplicate values and skip sending; requires the dp-kit interceptor; default false
Compared with the current `dpState`; duplicates are detected and not sent
-
delaynumberNoDelayed send; requires the dp-kit interceptor; default 0, in ms-
throttlenumberNoSend throttling (conflicts with debounce); requires the dp-kit interceptor; default 0, in ms-
debouncenumberNoSend debounce (conflicts with throttle); requires the dp-kit interceptor; default 0, in ms-
NoA per-call DP protocol converter; requires the dp-kit interceptor.
The key is the dpCode and the value is a `{ parser, formatter }` object:
- parser(dpValue: string) => any — parses the raw DP string into a structured object
- formatter(parsedValue: any) => string — serializes the structured object into a DP string
Affects only this invocation and does not override the global protocols configuration in createDpKit
-
typeCapability
export type Capability = number;
typeDevAttribute
export type DevAttribute = number;

Valid Values

DevInfo.schema.mode
ValueDescriptionSince
rw--
ro--
wr--
DevInfo.schema.property.type
ValueDescriptionSince
string--
bool--
value--
enum--
bitmap--
raw--
DevInfo.schema.type
ValueDescriptionSince
raw--
obj--
FunConfig.tyabirysr4_app
ValueDescriptionSince
follow--
--app-B1--
FunConfig.tyabis5d9w_app
ValueDescriptionSince
follow--
--app-M1--
LogConfig.level
ValueDescriptionSince
VERBOSE--
SUCCESS--
INFO--
WARN--
FATAL--

Examples

Add devices in bulk

import { SmartDevicesManager, createDpKit } from '@ray-js/panel-sdk';

const deviceManager = new SmartDevicesManager();
const dpKit = createDpKit({ protocols });

const result = await deviceManager.batchAdd([
  {
    key: 'lamp1',
    deviceId: 'xxx_device_id_1',
    interceptors: dpKit.interceptors, // Use structured DP with dp-kit
  },
  {
    key: 'lamp2',
    deviceId: 'xxx_device_id_2',
    interceptors: dpKit.interceptors,
    logConfig: { level: 'VERBOSE' }, // Enable detailed logs for this device only
  },
  {
    key: 'failedDevice',
    deviceId: 'invalid_device_id',
  },
], { concurrency: 5 });

if (result.failed.length > 0) {
  console.warn('Some devices failed to initialize:', result.failed);
}
// batchAdd return example:
{
  "success": {
    "lamp1": "<SmartDeviceModel>",
    "lamp2": "<SmartDeviceModel>"
  },
  "failed": [
    {
      "key": "failedDevice",
      "deviceId": "invalid_device_id",
      "error": "Device info not found for invalid_device_id"
    }
  ]
}