关于拦截器的使用,想要请教一下
关于拦截器的使用,想要请教一下
(问题描述(复现步骤):实现了一个拦截器,然后设置了dp点 synchronizeDevProperty:true,保存在云端,但是每次重启面板,面板好像不会以保存在云端的数据启动,不清楚如何查看下发dp点后,保存云端怎么样才算成功.
预期结果:给低功耗设备下发dp点之后,重启面板,面板能以下发的数据显示
实际结果:给低功耗设备下发dp点之后,重启面板,面板任然以低功耗上一次上报的数据显示)
Code: Select all
const structuredProps = useStructuredProps(state => ({
debugInfo: state.debug_raw,
}));
// 获取配置参数(需要立即下发的)
const configProps = useProps(state => ({
far_detection: state.far_detection,
r1threshold: state.r1th,
r2threshold: state.r2th,
r3threshold: state.r3th,
mr1threshold: state.mr1th,
mr2threshold: state.mr2th,
mr3threshold: state.mr3th,
lowpower: state.low_power_switch,
battery: state.battery_percentage,
presence: state.presence_state,
}));
我拦截器是只对调试信息做复杂协议解析,其他的dp点都是useProps获取的,设置了立即下发,忽略上报,保存云端
Code: Select all
VM65 dev-tools.js:1 [DEVTOOLS] The current debugging basic library version is 2.30.2
service.js:5 [audit-tool] Enabling experience rating...
service.js:5 [audit-tool] Watching experience rating end. undefined
app.tsx:20 === App did mount
composeLayout.tsx:24 === App onLaunch {path: 'pages/home/index', apiCategory: 'default', query: {…}}
redux-logger.js:1 action systemInfo/initializeSystemInfo @ 17:59:55.527 (in 0.20 ms)
redux-logger.js:1 action theme/updateThemeType @ 17:59:55.528 (in 0.20 ms)
service.socket.js:1 [webshell] socket connected service
index.ts:76 Parsed Radar Data: {mr1th: 6, mr2th: 4, mr3th: 3, r1th: 8, r2th: 6, …}
view.js:5 [View] [system] [Library] Page First Render Time: 572ms
view.js:5 [View] [system] [Library] Page FMP Time: 646ms
index.tsx:448 缓存的指令: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
index.tsx:442 低功耗状态: true
log.js:54 [2025/12/17 18:00:44.742] [INFO] SDM#publishDps by dp-kit: "data publish Object with Object"
log.js:54 [2025/12/17 18:00:44.745] [WARN] SDM#onDpDataChange by dp-kit: "data report Object from dp-kit"
log.js:54 [2025/12/17 18:00:44.746] [INFO] SDM#onDpDataChange by dp-kit: "[ignoreDpChangeInterceptor] ignore dp report has been enabled, trigger immediately."
log.js:54 [2025/12/17 18:00:46.268] [INFO] SDM#publishDps by dp-kit: "data publish Object with Object"
log.js:54 [2025/12/17 18:00:46.269] [WARN] SDM#onDpDataChange by dp-kit: "data report Object from dp-kit"
log.js:54 [2025/12/17 18:00:46.269] [INFO] SDM#onDpDataChange by dp-kit: "[ignoreDpChangeInterceptor] ignore dp report has been enabled, trigger immediately."
- 相关代码:
下面是发dp点的代码
Code: Select all
export const dpKit = createDpKit<SmartDeviceSchema>({ protocols: protocols as any, sendDpOption: { immediate: true, checkRepeat: true, ignoreDpDataResponse:{ whiteDpCodes: ['debug_raw'], debug: true,
}, synchronizeDevProperty:true, },
}); const deviceOptions = { interceptors: dpKit.interceptors, } as SmartDeviceModel<SmartDeviceSchema>['options'];Code: Select all
const ConfigCard = ({ dpCode, label, unit = '' }) => { const actions = useActions(); const dpValue = useProps((state) => state[dpCode]); const dpSchema = useDpSchema(); const lastChangeRef = useRef(Date.now()); const handleChange = (value: number) => { const now = Date.now(); // 防抖:300ms内只发一次 if (now - lastChangeRef.current < 300) return; lastChangeRef.current = now; // 立即下发 actions[dpCode].set(value); // 记录到云端缓存 addCommand( getLaunchOptionsSync().query.deviceId, JSON.stringify({ [dpCode]: value }), Date.now() ); }; return ( <View className={styles.configCard}> <Text className={styles.configLabel}> {label}: {dpValue || 0}{unit} </Text> <Slider max={dpSchema[dpCode]?.property?.max || 1000} min={dpSchema[dpCode]?.property?.min || 0} value={dpValue || 0} step={dpSchema[dpCode]?.property?.step || 1} onChange={(event) => handleChange(event.detail.value)} activeColor="#00e5ff" /> </View> ); };
Tuya MiniApp IDE 版本信息:0.10.4
App 应用版本信息:智能生活7.0.0
@ray-js/ray, @ray-js/panel-sdk的版本 "@ray-js/ray": "1.7.56", "@ray-js/panel-sdk": "1.13.1"