SmartDeviceModel.onDeviceInfoUpdated(listener: Function)

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

描述

监听智能设备信息变更事件(包括设备名称、DP 名称等变更)

参数

参数类型必填说明
listener(data: DeviceInfoChanged) => number是事件回调,接收包含 deviceId、变更数据等信息的参数

返回值

类型:number
监听器 ID,用于通过 offDeviceInfoUpdated 取消监听

引用对象

typeDeviceInfoChanged设备信息变更事件回调参数
属性类型必填描述
deviceIdstring是设备 id
否变化的功能点数据(可能为空)
typeDpState功能点状态对象,key 为功能点 code,value 为功能点值
export type DpState = Record<string, DpValue>;
typeDpValue功能点值类型,可能为 boolean、number、string
export type DpValue = boolean | number | string;

示例代码

示例

const id = device.onDeviceInfoUpdated((data) => {
  console.log('设备信息变更:', data.deviceId);
});
// 取消监听
device.offDeviceInfoUpdated(id);