SmartDeviceModel.publishDps(data: Record<string, DpValue>, options?: SendDpOption)

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

Description

Control multiple smart device DPs in batch, built on top of ty.device.publishDps

Parameters

ParameterTypeRequiredDescription
dataRecord<string, DpValue>YesKey-value pairs of DPs to publish. Keys are DP codes; value types must be derived from the device’s DP schema: bool → boolean, value → number, enum → property.range literal union, bitmap → number, string/raw → string
NoPublish options. deviceId and dps are no longer required parameters. SendDpOption is an advanced configuration provided by dp-kit interceptors

Return Value

Type: Promise<boolean>
Whether the publish was successful

Referenced Types

typeDpValueDatapoint value type, which can be boolean, number, or string.
export type DpValue = boolean | number | string;

Examples

Basic command sending.

// Constrain input params based on the device DP schema
await device.publishDps({ switch_led: true });               // boolean
await device.publishDps({ work_mode: 'colour' });            // 'white' | 'colour' (IDE auto-completion)
await device.publishDps({ brightness: 500 });                // number (clamped to 10~1000 at runtime)
await device.publishDps({ switch_led: true, brightness: 800 }); // Supports batch publishing

Advanced dp-kit interceptor configuration (requires use with createDpKit).

// Immediately update local state (optimistic update, without waiting for device report)
await device.publishDps({ brightness: 800 }, { immediate: true });

// Throttle 300ms, suitable for high-frequency interactions like sliders
await device.publishDps({ brightness: 800 }, { throttle: 300 });

// Debounce 500ms, send only after user stops interacting
await device.publishDps({ brightness: 800 }, { debounce: 500 });

// Do not send duplicate values to avoid redundant commands
await device.publishDps({ switch_led: true }, { checkRepeat: true });

// Ignore the device report after this publish (prevent slider bounce-back)
await device.publishDps({ brightness: 800 }, { ignoreDpDataResponse: true });

// Combine options
await device.publishDps(
  { brightness: 800 },
  { immediate: true, throttle: 300, ignoreDpDataResponse: true },
);