SmartDevicesManager.add(config: AddConfig)

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

Description

Add a single device instance and complete initialization. If init() has not been called, it will auto-init first for backward compatibility. Typically used to dynamically add one associated device; throws an error if the deviceId already exists.

Parameters

ParameterTypeRequiredDescription
YesDevice config

Return Value

Type: Promise<SmartDeviceModel>
Initialized device instance

Referenced Types

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

Dynamically add a single device

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

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

const lamp = await deviceManager.add({
  key: 'lamp1',
  deviceId: 'xxx_device_id',
  interceptors: dpKit.interceptors,
  logConfig: { level: 'VERBOSE' },
});

lamp.getDevInfo();