SmartDeviceModel.onDpDataChange(listener: Function)

Requires:
@ray-js/panel-sdk≥1.0.0

Description

Listen for smart device DP change events

Parameters

ParameterTypeRequiredDescription
listener(data: DpsChanged) => numberYesEvent callback that receives parameters containing deviceId, dps (changed DP ID→value mapping), etc.

Return Value

Type: number
Listener ID used to unsubscribe via offDpDataChange

Referenced Types

typeDpsChangedDP change event callback parameters (single device)
PropertyTypeRequiredDescription
deviceIdstringYesDevice ID
gwIdstringNoGateway device ID for a sub-device; absent for non-sub-devices
YesChanged DP data, where the key is the DP ID and the value is the DP value
NoTimestamp of the DP data change (may be empty)

Examples

Example

const id = device.onDpDataChange((data) => {
  console.log('DP change:', data.dps);
});
// Unsubscribe
device.offDpDataChange(id);