SmartDeviceModel(options?: SmartDeviceModelOptions)

版本要求:
@ray-js/panel-sdk≥1.0.0
所有 DP 相关 API 的类型均由泛型 S(ReadonlyDpSchemaList)在编译期推导,展开完整说明
所有 DP 相关 API 的类型均由泛型 S(ReadonlyDpSchemaList)在编译期推导,
S 来自业务项目 devices/schema.ts 中 as const 声明的 Schema 常量。Schema property.type 与 TypeScript 类型映射:
- bool → boolean(true/false)
- value → number(受 property.min/max/step 运行时约束,类型仅为 number)
- enum → props 为 string;publishDps 入参为 property.range 字面量联合(如 'white' | 'colour')
- bitmap → number(位运算值,配合 actions 的 on(idx)/off(idx) 操作指定 bit 位)
- string → string
- raw(外层 type='raw')→ stringSchema 必须使用 as const 断言,否则字面量类型推导退化。

描述

智能设备模型,提供设备功能点状态管理、事件监听、指令下发等核心能力

参数

参数类型必填说明
否设备模型初始化配置,包含 abilities(高级能力列表)和 interceptors(事件拦截器)等选项

返回值

类型:SmartDeviceModel
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;

合法值

LogConfig.level
值说明最低版本
VERBOSE--
SUCCESS--
INFO--
WARN--
FATAL--
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--

方法

方法名说明
init异步初始化智能设备后再返回其实例
onInitialized注册智能设备模型初始化完毕事件回调
offInitialized取消智能设备模型初始化完毕事件监听
getDevInfo获取智能设备信息,基于 ty.device.getDeviceInfo 实现
getDpSchema获取智能设备 DP Schema(功能点描述)映射表
getDpState获取智能设备功能点状态
getNetwork获取智能设备所处环境的网络状态
getBluetooth获取智能设备所处环境的蓝牙状态
onDpDataChange监听智能设备 DP 功能点变更事件
onDeviceOnlineStatusUpdate监听智能设备上下线状态变更
onDeviceInfoUpdated监听智能设备信息变更事件(包括设备名称、DP 名称等变更)
onNetworkStatusChange监听网络状态变化事件
onBluetoothAdapterStateChange监听蓝牙适配器状态变化事件
offDpDataChange取消监听智能设备 DP 功能点变更事件
offDeviceOnlineStatusUpdate取消监听智能设备上下线状态变更
offDeviceInfoUpdated取消监听智能设备信息变更事件
offNetworkStatusChange取消监听网络状态变化事件
offBluetoothAdapterStateChange取消监听蓝牙适配器状态变化事件
publishDps批量控制智能设备 DP 功能点,基于 ty.device.publishDps 拓展实现
queryDps主动查询设备功能点状态(不支持群组)
destroy销毁当前智能设备实例,同时销毁所有事件监听器

示例代码

基础初始化

import { SmartDeviceModel } from '@ray-js/panel-sdk';
import { defaultSchema } from './devices/schema';

type Schema = typeof defaultSchema;
const device = new SmartDeviceModel<Schema>();
await device.init();

// 初始化后即可访问设备状态
const props = device.getDpState();   // { switch_led: boolean, work_mode: string, ... }
const devInfo = device.getDevInfo(); // 设备信息