SmartGroupModel.onDpDataChange(listener: Function)

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

Description

Listen for DP change events in group devices

Parameters

ParameterTypeRequiredDescription
listener(data: GroupDpsChanged) => numberYesEvent callback that receives parameters including groupId, dps (mapping of changed DP IDs to values), etc.

Return Value

Type: number
Listener ID, used to cancel via offDpDataChange

Referenced Types

typeGroupDpsChangedDP change event callback parameters (group device)
PropertyTypeRequiredDescription
groupIdstringYesGroup ID
YesChanged DP data, where the key is the DP ID and the value is the DP value
typeDpStateDatapoint status object, where the key is the datapoint code and the value is the datapoint value.
export type DpState = Record<string, DpValue>;
typeDpValueDatapoint value type, which can be boolean, number, or string.
export type DpValue = boolean | number | string;

Examples

Example

const id = group.onDpDataChange((data) => {
  console.log('DP changed:', data.dps);
});
// Unregister when needed
group.offDpDataChange(id);