Gateway Features

Last Updated on : 2024-06-05 03:14:36download

This topic describes the gateway service APIs that are used to implement features for your gateway product.

Prerequisites

To use gatewayApi, you must install dependencies first.

Bind and unbind a Bluetooth LE sub-device

Name

bleSubDevRelationUpdate

Description

Binds a Bluetooth Low Energy (LE) device with a gateway and unbinds it from the gateway.

Request parameters

Parameter
Data type
Description
Required
sourceMeshId String The value of meshId or gateway ID associated with the target sub-devices. Pass in the value of sigmeshId to bind the sub-device with the gateway. Pass in the gateway ID to unbind the sub-devices from the gateway. Yes
nodes BleNodeInfo[] The list of Bluetooth LE devices. Yes
targetMeshId String | Null The value of meshId of the gateway. Pass in the gateway ID to bind the sub-devices with the gateway. Pass in null to unbind the sub-devices from the gateway. Yes

BleNodeInfo

Parameter
Data type
Description
devId String The device ID of the Bluetooth LE device.
uuid String The UUID of the Bluetooth LE device.

Sample request

import { gatewayApi } from '@tuya/tuya-panel-api';
import { GatewayUtils } from '@tuya/tuya-panel-gateway-sdk';
import { TYSdk } from 'tuya-panel-kit';

const { bleSubDevRelationUpdate } = gatewayApi.relationApi;
const { isBlueSub, getAllDevice, isAddableDevice } = GatewayUtils;

// The list of devices that belong to the home.
const devList = await getAllDevice();

// The list of devices that can be added to the gateway.
const addableDeviceList = devList.filter(subDev =>
  isAddableDevice({
    devInfo: subDev,
    gatewayDevInfo: TYSdk.devInfo,
  })
);

// The Bluetooth LE devices that can be added to the gateway.
const bleDevList = addableDeviceList.filter(device => isBlueSub(device.capability));

// The node information required to combine API methods.
const nodes = bleDevList.map(device => ({ devId: device.devId, uuid: device.uuid }));

/**
 * desc: Binds a Bluetooth LE sub-device.
 */
bleSubDevRelationUpdate(TYSdk.devInfo.sigmeshId, nodes, TYSdk.devInfo.devId)
  .then(response => {
    console.log(response);
  })
  .catch();

/**
 * desc: Unbinds a Bluetooth LE device.
 */
bleSubDevRelationUpdate(TYSdk.devInfo.devId, nodes, null)
  .then(response => {
    console.log(response);
  })
  .catch();

Bind and unbind Bluetooth mesh devices

Name

sigmeshSubDevRelationUpdate

Description

Binds Bluetooth mesh devices with a gateway and unbinds them from the gateway.

Request parameters

Parameter
Data type
Description
Required
sourceMeshId String The value of meshId or gateway ID associated with the target sub-devices. Pass in the value of meshId of sub-devices to bind them with the gateway. Pass in the gateway ID to unbind the sub-devices from the gateway. Yes
nodeIds String[] The list of node IDs specified by nodeId for the Bluetooth mesh devices. Yes
targetMeshId String | Null The value of meshId of the gateway. Pass in the gateway ID to bind the sub-devices with the gateway. Pass in null to unbind the sub-devices from the gateway. Yes

Sample request

import { gatewayApi } from '@tuya/tuya-panel-api';
import { GatewayUtils } from '@tuya/tuya-panel-gateway-sdk';
import { TYSdk } from 'tuya-panel-kit';

const { sigmeshSubDevRelationUpdate } = gatewayApi.relationApi;
const { isSigmeshSub, getAllDevice, isAddableDevice } = GatewayUtils;

// The list of devices that belong to the home.
const devList = await getAllDevice();
// The list of devices that can be added to the gateway.
const addableDeviceList = devList.filter(subDev =>
  isAddableDevice({
    devInfo: subDev,
    gatewayDevInfo: TYSdk.devInfo,
  })
);
// The Bluetooth mesh devices that can be added to the gateway.
const sigmeshDevList = addableDeviceList.filter(device => isSigmeshSub(device.capability));

// The node information required to combine API methods.
const nodeIds = sigmeshDevList.map(device => device.nodeId);

// Scans for the Bluetooth mesh devices with `meshId`.
const deviceWithMeshId = sigmeshDevList.find(device => device.meshId !== undefined);

// If no devices are found, the system cannot proceed with subsequent steps.
if (!deviceWithMeshId) return;

/**
 * desc: Binds a Bluetooth mesh device.
 */
sigmeshSubDevRelationUpdate(deviceWithMeshId.meshId, nodeIds, TYSdk.devInfo.devId)
  .then(response => {
    console.log(response);
  })
  .catch();

/**
 * desc: Unbinds a Bluetooth mesh device.
 */
sigmeshSubDevRelationUpdate(TYSdk.devInfo.devId, nodeIds, null)
  .then(response => {
    console.log(response);
  })
  .catch();

Unbind and bind beacon devices

Name

beaconSubDevRelationUpdate

Description

Binds beacon devices with a gateway and unbinds them from the gateway.

Request parameters

Parameter
Data type
Description
Required
sourceMeshId String The gateway ID associated with the target sub-device. Pass in null to bind the sub-devices with the gateway. Pass in the gateway ID to unbind the sub-devices from the gateway. Yes
nodeIds BeaconNodeInfo[] The list of beacon devices. Yes
targetMeshId String | Null The value of meshId of the gateway. Pass in the gateway ID to bind the sub-devices with the gateway. Pass in null to unbind the sub-devices from the gateway. Yes

BeaconNodeInfo

参数
数据类型
说明
devId String The device ID of the beacon device.
mac String The MAC address of the beacon device. The value must be in lower case and not separated with colons (;). Example: 0800200a8c6d.

Sample request

import { gatewayApi } from '@tuya/tuya-panel-api';
import { GatewayUtils } from '@tuya/tuya-panel-gateway-sdk';
import { TYSdk } from 'tuya-panel-kit';

const { beaconSubDevRelationUpdate } = gatewayApi.relationApi;
const { isBeaconSub, getAllDevice, isAddableDevice, transformMac } = GatewayUtils;

// The list of devices that belong to the home.
const devList = await getAllDevice();

// The list of devices that can be added to the gateway.
const addableDeviceList = devList.filter(subDev =>
  isAddableDevice({
    devInfo: subDev,
    gatewayDevInfo: TYSdk.devInfo,
    // Set the value to `true`. Otherwise, the result will not include beacon devices.
    supportBeacon: true,
  })
);

// The list of beacon devices.
const beaconDevList = addableDeviceList.filter(device => isBeaconSub(device.capability));

// The node information required to combine API methods.
const nodeIds = beaconDevList.map(device => ({
  devId: device.devId,
  mac: transformMac(device.mac, true, false),
}));

/**
 * desc: Binds a beacon device.
 */
beaconSubDevRelationUpdate(null, nodeIds, TYSdk.devInfo.devId)
  .then(response => {
    console.log(response);
  })
  .catch();

/**
 * desc: Unbinds a beacon device.
 */
beaconSubDevRelationUpdate(TYSdk.devInfo.devId, nodeIds, null)
  .then(response => {
    console.log(response);
  })
  .catch();