SmartDevicesManager.add(config: AddConfig)

版本要求:
@ray-js/panel-sdk≥1.16.0

描述

添加单个设备实例并完成初始化。 若尚未 init() 会先自动 init(),保证向后兼容。 常见场景是动态添加单台关联设备;若 deviceId 已存在则抛出错误。

参数

参数类型必填说明
是设备配置

返回值

类型:Promise<SmartDeviceModel>
初始化完成的设备实例

引用对象

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
属性类型必填描述
是当前设备功能点状态
是新的设备功能点状态
action"init" | "onDpDataChange" | "onDeviceInfoUpdated" | "dp-kit"是拦截器动作
typeGetSmartDeviceModelDevInfo
属性类型必填描述
dpCodesobject是
dpsobject是
idCodesobject是
codeIdsobject是
schemaS是
typeSmartDeviceModelAbilitySmartDeviceModel 的 abilities 容器类型,仅用于泛型约束与内部组合。
export type SmartDeviceModelAbility<A extends SmartDeviceAbility = SmartDeviceAbility> = {
  [abilityName: string]: A;
};
typePublishDpsOptionspublishDps 的底层选项类型,供 SDK 内部请求链复用。
属性类型必填描述
否
typeDpValue功能点值类型,可能为 boolean、number、string
export type DpValue = boolean | number | string;
typeSendDpOptionDP 下发选项,可作为 createDpKit 的全局默认配置,也可在单次 publishDps / action 调用时覆盖。 全局 `sendDpOption` 适合声明产品级默认行为; 单次下发传入的 options 适合临时覆盖节流、防抖、协议解析或乐观更新策略。 注:依赖 dp-kit 拦截器才可使用。
属性类型必填描述最低版本
immediateboolean否是否立即触发 state 更新,必须依赖 dp-kit 拦截器才可使用-
否是否忽略 DP 功能点上报,默认 falsev1.11.0
否是否将 dpData 和云端设备属性同步,默认 falsev1.11.0
orderedboolean否多个 DP 是否按对象里的顺序下发,必须依赖 dp-kit 拦截器才可使用,默认 false-
checkRepeatboolean否是否进行重复值判断不下发,必须依赖 dp-kit 拦截器才可使用,默认 false
与当前 `dpState` 进行比较,重复值检出不下发
-
delaynumber否延迟下发,必须依赖 dp-kit 拦截器才可使用,默认 0,单位 ms-
throttlenumber否下发节流 (与防抖冲突),必须依赖 dp-kit 拦截器才可使用,默认 0,单位 ms-
debouncenumber否下发防抖 (与节流冲突),必须依赖 dp-kit 拦截器才可使用,默认 0,单位 ms-
否单次下发时临时指定的 DP 协议转换器,必须依赖 dp-kit 拦截器才可使用。
key 为 dpCode,value 为 `{ parser, formatter }` 对象:
- parser(dpValue: string) => any — 将原始 DP 字符串解析为结构化对象
- formatter(parsedValue: any) => string — 将结构化对象序列化为 DP 字符串
仅影响本次调用,不覆盖 createDpKit 中的全局 protocols 配置
-
typeCapability
export type Capability = number;
typeDevAttribute
export type DevAttribute = number;

合法值

DevInfo.schema.mode
值说明最低版本
rw--
ro--
wr--
DevInfo.schema.property.type
值说明最低版本
string--
bool--
value--
enum--
bitmap--
raw--
DevInfo.schema.type
值说明最低版本
raw--
obj--
FunConfig.tyabirysr4_app
值说明最低版本
follow--
--app-B1--
FunConfig.tyabis5d9w_app
值说明最低版本
follow--
--app-M1--
LogConfig.level
值说明最低版本
VERBOSE--
SUCCESS--
INFO--
WARN--
FATAL--

示例代码

动态添加单个设备

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();