Device SupportGroup Not Support

useCustomAlarm

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

Method signature
useCustomAlarm()

Description

Get the device’s custom alarm list and CRUD operations; supports single devices only, not groups

Parameters

None

Return Value

Type: CustomAlarmResult
Custom alarm data, loading state, and management methods

Referenced Types

typeCustomAlarmResult
PropertyTypeDescription
[]Custom alarm list for the device
loadingbooleanWhether the device’s custom alarm list is loading
(options: ) => Promise<[]>Query the device’s custom alarm list by device ID
(options: ) => Promise<[, ]>Add or edit a custom alarm rule
(options: ) => Promise<[boolean, ]>Enable or disable custom alarm rules
(options: ) => Promise<[boolean, ]>Delete custom alarm rules
typeOperator
type Operator = '==' | '<' | '>' | '<=' | '>=';
typeDpValueDatapoint value type, which can be boolean, number, or string.
export type DpValue = boolean | number | string;

Valid Values

Operator
ValueDescriptionSince
==--
<--
>--
<=--
>=--

Examples

Example

import { useCustomAlarm } from '@ray-js/panel-sdk';

function AlarmPage() {
  const { data, loading, getCustomAlarmList, setCustomAlarmStatus } = useCustomAlarm();

  React.useEffect(() => {
    getCustomAlarmList();
  }, []);

  const handleToggle = (item) => (value) => {
    setCustomAlarmStatus({ bindId: item.bindId, enable: value });
  };

  return data.map(item => (
    <Switch key={item.bindId} checked={item.enable} onChange={handleToggle(item)} />
  ));
}