useDevicesActions()

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

Description

Get the collection of DP action methods for associated devices

Parameters

None

Return Value

Type: { [key: string]: DpActions }
A collection of device action methods; keys are device identifiers and values are the device’s actions object.
Each device’s actions are used the same as single-device useActions

Referenced Types

interfaceDpActions
PropertyTypeDescription
All types expose this method to send a DP point, but the value you pass depends on the DP type
Only bool and bitmap types have this method; enable the DP or set the specified bit
Only bool and bitmap types have this method; disable the DP or clear the specified bit
Available only for bool and bitmap types; toggle the datapoint or flip the specified bit
Available only for the value type; increment by the datapoint's step
Available only for value type; decrease by the current DP step (step)
Available only for enum type; switch to the previous enum value
Available only for enum type; switch to the next enum value
Available only for enum type; switch to a random enum value
typeIgnoreDpChangeInterceptorOptionsConfiguration option to ignore the DP data change interceptor Used to configure the debounce mechanism for DP reporting events on the device panel, preventing immediate responses after panel operations from affecting user experience or business logic
PropertyTypeDescription
whiteDpCodesstring[]DP whitelist; reports will not be ignored
timeoutnumberDebounce timeout check, in milliseconds, default 5000
- The maximum time between sending a DP from the panel and receiving the DP reply; dpDataChange is triggered only if this is exceeded.
- Used to debounce DP reporting events
Custom ignore rules
> Highest priority; when configured, whiteDpCodes and timeout become ineffective
typeDevPropInterceptorOptions
PropertyTypeDescription
blackDpCodesstring[]DP blacklist; will not be synchronized to the cloud
Default device state on first entry; supports async initialization
throttlenumberSend throttling, in milliseconds, defaults to 0
If set to 0, throttling is disabled.
typeCustomRawDpMapCustom DP protocol converter for transforming between raw DP strings and structured objects. Suitable for composite DPs of type raw/string (e.g., a light's colour_data "00ff003e8"), splitting a single string into multiple semantic fields (e.g., { hue, saturation, value }).
PropertyTypeDescription
Parse the raw DP string reported by the device into a structured object
Serialize the structured object into a DP string to be sent to the device
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

Control various DP types on the specified device

// devices/schema.ts — as const is the cornerstone of type inference; set is a generic method, others are type-specific shortcuts
import { useDevicesActions, useDevicesProps } from '@ray-js/panel-sdk';

export const schema = [
  { code: 'switch_led',  property: { type: 'bool' }, type: 'obj', mode: 'rw', id: 1, name: 'Switch' },
  { code: 'brightness',  property: { type: 'value', min: 10, max: 1000, step: 1 }, type: 'obj', mode: 'rw', id: 2, name: 'Brightness' },
  { code: 'work_mode',   property: { type: 'enum', range: ['white', 'colour'] }, type: 'obj', mode: 'rw', id: 3, name: 'Mode' },
  { code: 'fault',       property: { type: 'bitmap', maxlen: 8 }, type: 'obj', mode: 'ro', id: 4, name: 'Fault' },
  { code: 'colour_data', property: { type: 'string', maxlen: 255 }, type: 'obj', mode: 'rw', id: 5, name: 'Color' },
] as const;

export default function MultiDeviceControl() {
  const actions = useDevicesActions();
  // Recommended: select only the required state to avoid unnecessary re-renders due to unrelated changes
  const mainSwitch = useDevicesProps(props => props.main?.switch_led);

  const handleToggle = () => {
    // ✅ set — generic for all types
    actions.main?.switch_led.set(true);            // bool
    actions.main?.brightness.set(500);             // value
    actions.main?.work_mode.set('colour');         // enum (IDE hints 'white' | 'colour')
    actions.main?.fault.set(3);                    // number(bitmap)
    actions.main?.colour_data.set('000003e803e8'); // string

    // For bool: on / off / toggle
    actions.main?.switch_led.toggle();
    actions.main?.switch_led.on();
    actions.main?.switch_led.off();

    // For value: inc / dec (step by step, auto-clamped to min~max)
    actions.main?.brightness.inc();               // +1 (default step)
    actions.main?.brightness.dec(100);            // -100

    // For enum: prev / next / random
    actions.main?.work_mode.next();               // Switch to the next enum value
    actions.main?.work_mode.prev();

    // For bitmap: on(idx) / off(idx) / toggle(idx)
    actions.main?.fault.on(0);                    // Set bit 0
    actions.main?.fault.off(1);                   // Clear bit 1
    actions.main?.fault.toggle(2);                // Toggle bit 2
  };

  return (
    <View onClick={handleToggle}>
      <Text>Main device: {mainSwitch ? 'On' : 'Off'}</Text>
    </View>
  );
}