SmartDeviceModel.publishDps(data: Record<string, DpValue>, options?: SendDpOption)

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

描述

批量控制智能设备 DP 功能点,基于 ty.device.publishDps 拓展实现

参数

参数类型必填说明
dataRecord<string, DpValue>是要下发的功能点键值对。键为 DP Code,值类型需要根据设备的功能点 Schema 推导 bool → boolean, value → number, enum → property.range 字面量联合, bitmap → number, string/raw → string
否下发配置选项,其中 deviceId、dps 不再是必传参数,SendDpOption 类型为 dp-kit 拦截器提供的高阶配置

返回值

类型:Promise<boolean>
是否下发成功

引用对象

typeDpValue功能点值类型,可能为 boolean、number、string
export type DpValue = boolean | number | string;

示例代码

基础下发

// 基于设备功能点 Schema 定义约束入参
await device.publishDps({ switch_led: true });               // boolean
await device.publishDps({ work_mode: 'colour' });            // 'white' | 'colour'(IDE 自动提示)
await device.publishDps({ brightness: 500 });                // number(运行时 clamp 到 10~1000)
await device.publishDps({ switch_led: true, brightness: 800 }); // 支持批量下发

dp-kit 拦截器高阶配置(需配合 createDpKit 使用)

// 立即更新本地状态(乐观更新,不等待设备上报)
await device.publishDps({ brightness: 800 }, { immediate: true });

// 节流 300ms,适用于滑动条等高频操作场景
await device.publishDps({ brightness: 800 }, { throttle: 300 });

// 防抖 500ms,用户停止操作后才下发
await device.publishDps({ brightness: 800 }, { debounce: 500 });

// 重复值不下发,避免无意义的指令
await device.publishDps({ switch_led: true }, { checkRepeat: true });

// 忽略本次下发后的设备上报(防止滑动条回弹)
await device.publishDps({ brightness: 800 }, { ignoreDpDataResponse: true });

// 组合使用
await device.publishDps(
  { brightness: 800 },
  { immediate: true, throttle: 300, ignoreDpDataResponse: true },
);