device.onDpDataChange
功能描述
dp 点变更
需引入
DeviceKit
,且在>=1.2.6
版本才可使用
使用
Ray 中使用
import { device } from '@ray-js/ray'
const { onDpDataChange } = device
onDpDataChange({ ... })
原生小程序中使用
const { onDpDataChange } = ty.device
onDpDataChange({ ... })
体验 Demo
智能生活App扫码进行体验
Demo下载地址
→
(opens in a new tab)
参数
function listener dp 点变更 参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
deviceId | string | 是 | dps 对应的设备 id | |
gwId | string | 是 | 子设备对应的网关设备 id,可以根据此进行网关面板的状态刷新 | |
dps | any | 是 | dps 变化的数据 | |
dpsTime | any | 否 | dpsTime dp 变化的时间戳(可能为空)最低版本4.11.0 | |
options | any | 是 | options 预留的标记位,后续可以区分来源等 |
代码示例
请求示例
// Ray调用方式
import {
onDpDataChange,
getLaunchOptionsSync,
registerDeviceListListener
} from '@ray-js/ray';
// 原生调用方式
const { onDpDataChange, registerDeviceListListener } = ty.device;
const { getLaunchOptionsSync } = ty;
// 启动参数中获取设备 id
const {
query: { deviceId }
} = getLaunchOptionsSync();
const _onDpDataChange = (event) => {
console.log(event);
};
registerDeviceListListener({
deviceIdList: [deviceId],
success: () => {
console.log('registerDeviceListListener success');
},
fail: (error) => {
console.log('registerDeviceListListener fail', error);
}
});
onDpDataChange(_onDpDataChange);
成功示例
{
"dpsTime": {
"20": 1732243243000
},
"gwId": "device_id",
"dps": {
"20": true
},
"deviceId": "device_id"
}
常见问题
Q:为什么调用了 onDpDataChange 之后,无法收到消息?
A:需要先调用 registerDeviceListListener 注册设备列表监听器,才能收到设备相关消息。
此页内容是否对您有帮助?
是
意见反馈