English
English
简体中文
Contact Us
Register
Log In
layoutIndex

API

Last Updated on : 2022-03-01 07:54:59download

Panel SDK Method

This topic mainly describes how to control the smart devices quickly through the panel SDK. For more information about cloud interfaces, see other documents under the directory of Common SDK Development.

Overview

Panel SDK provides quick and complete solutions to connect Tuya products. Panel SDK provides methods for App SDK-based capabilities, such as device control, timing tasks, and event monitoring, and methods for jumping to Tuya Smart app modules, such as scenario module, a network configuration module, and user center. Panel SDK can achieve complete functions through simple calls, so developers can connect Tuya products more quickly.

Requesting interface data

TYSdk.apiRequest()

Request parameter

Name Type Description Required
a string Api name Yes
postData object Parameters to be passed Yes
version string Api version No
// 4.x
TYSdk.apiRequest(a, postData, version)
  .then(data =>
    console.log('data',data);
  )
  .catch(error =>
    console.log('error',error);
  );

// 2.x
TYSdk.apiRequest({
  a,
  postData,
  v,
})
  .then(data => {
    console.log('data :>> ', data);
  })
  .catch(error => {
    console.log('error :>> ', error);
  });

Event method

Monitoring method

Request parameter

Name Type Description Required
yourEventName string Event name Yes
yourHandler function Listen for callbacks triggered successfully No

Request example

TYSdk.event.on(yourEventName, yourHandler); // Start monitoring event

TYSdk.event.off(yourEventName, yourHandler); // Cancel monitoring event

TYSdk.event.emit(yourEventName, yourHandler); // Actively trigger the event

Frequently-used event name

/**
 * @desc
 * type: dpData  Data point (DP) status changes, such as changes of device DP status.,payload is dpData
 * type: devInfo  Device information changes, such as changes of device name, payload is devInfo.
 * type: deviceOnline Device online status changes, payload is boolean.
 */
on(
    event: 'deviceDataChange',
    callback: (data: {
        type: 'dpData' | 'devInfo' | 'deviceOnline';
        payload: Record<string, DpValue> | DevInfo | boolean;
    }) => void,
): void;
/**
 * @desc Notification of app network status changes.
 */
on(event: 'networkStateChange', callback: (data: { appOnline: boolean }) => void): void;
/**
 * @desc Notification of timing status changes.
 */
on(event: 'linkageTimeUpdate', callback: (data: {}) => void): void;
/**
 * @desc  Local area network device status change notification.
 */
on(event: 'deviceLocalStateChange', callback: (data: { state: boolean }) => void): void;
/**
 * @desc Notification of Bluetooth online status changes.
 */
on(event: 'bluetoothChange', callback: (value: boolean) => void): void;
/**
 * @desc Route change event of inner encapsulation for NavigatorLayout. It is called each time when pages are switched.
 */
on(event: 'NAVIGATOR_ON_WILL_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;
/**
 * @desc Route change event of inner encapsulation for NavigatorLayout. It is called each time when pages are switched or initialized.
 */
on(event: 'NAVIGATOR_ON_DID_FOCUS', callback: (route: DeprecatedNavigatorRoute) => void): void;

Note: When executing componentWillUnmount, cancel monitoring event.

Equipment information acquisition

TYSdk.devInfo

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
DevInfo DevInfo Get device information

The common fields will be explained below, for more comprehensive information, please refer to DEVINFO type definition

  • name: Device name.
  • productId: Product ID.
  • uiId: The panel ID corresponding to the current product.
  • bv: Hardware baseline version.
  • devId: Device ID.
  • gwId: Gateway ID. When it comes to a single device, the devId is usually equal to gwId.
  • ability: Only used by Bluetooth devices. The value should be 5 when it is used for Single Bluetooth Low Energy (Bluetooth LE) devices.
  • appOnline: Whether the app is online.
  • deviceOnline: Whether the device is online.
  • isLocalOnline: Whether the LAN is online.
  • isShare: Whether it is a shared device.
  • groupId: Group device ID, which is used to determine whether it is a group device.
  • networkType: The online type of the device.
  • schema: The data point of the product to which the device belongs. For more information about the data point, see DP explanation.
  • state: The status of DP.
  • capability: The capability type of the device, indicating what capabilities the device supports, such as Zigbee, infrared, and Bluetooth.

|Type|Wi-Fi|Wired cable| GPRS | NB-IoT | Bluetooth LE | Bluetooth LE mesh | Zigbee | Infrared | 433 | SIG Mesh |
|-|-|-|-|-|-|-|-|-|-|-|-|
|Bit|0|1|2|3|10|11|12|13|14|15|
|Capability value|1|2|4|8|1024|2048|4096|8192|16384|32768|

Request example

console.log('TYSdk.devInfo: ', TYSdk.devInfo);

Device method

TYSdk.device.checkDpExist()

Request parameter

Name Type Description Required
idOrCode string dpId or dpCode Yes

Return parameter

Name Type Description
isExit boolean Check if the DP exists

Request example

TYSdk.device.checkDpExist(idOrCode);

TYSdk.device.getDeviceInfo()

Return parameter

Name Type Description
DevInfo DevInfo Get device information

Request example

TYSdk.device.getDeviceInfo()
  .then((data: DevInfo) => {
    console.log('data :>> ', data);
  })
  .catch(error => {
    console.log('error :>> ', error);
  });

TYSdk.device.getDeviceState()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
DpState `{ dpCode: number string

Request example

TYSdk.device.getDeviceState()
.then((data: DpState) => {
    console.log('data :>> ', data);
  })
  .catch(error => {
    console.log('error :>> ', error);
  });

TYSdk.device.getDpCodeById()

Request parameter

Name Type Description Required
dpId `string number` dpId

Return parameter

Name Type Description
dpCode string Obtain dpCode according to dpId

Request example

TYSdk.device.getDpCodeById(dpId);

TYSdk.device.getDpCodes()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
dpCodes string[] Get all dpCodes of the device

Request example

TYSdk.device.getDpCodes();

TYSdk.device.getDpDataFromDevice()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
idOrCode `string number` dpId or dpCode

Return parameter

Name Type Description
DpState `{ dpCode: number string

Request example

TYSdk.device.getDpDataFromDevice(idOrCode)
  .then((data: DpState) => {
    console.log('data :>> ', data);
  })
  .catch(error => {
    console.log('error :>> ', error);
  });

TYSdk.device.getDpIdByCode()

Request parameter

Name Type Description Required
dpCode string dpCode Yes

Return parameter

Name Type Description
dpId string Obtain dpId according to dpCode

Request example

TYSdk.device.getDpIdByCode(dpCode);

TYSdk.device.getDpSchema()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
dpCode string dpCode No

Return parameter

Name Type Description
DpSchema DpSchema Get the schema information of the DP corresponding to the device

Request example

TYSdk.device.getDpSchema(dpCode);

TYSdk.device.getState()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
idOrCode `string number` dpId or dpCode

Return parameter

Name Type Description
dpState `{ dpCode: number string

Request example

TYSdk.device.getState(idOrCode);

TYSdk.device.isBleDevice()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
isBleDevice boolean Is it a Bluetooth device

Request example

TYSdk.device.isBleDevice();

TYSdk.device.isLocalLAN()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
isLocalLAN boolean LAN or not

Request example

TYSdk.device.isLocalLAN();

TYSdk.device.isMeshDevice()

Return parameter

Name Type Description
isMeshDevice boolean Whether it is a device that supports networking

Request example

TYSdk.device.isMeshDevice();

TYSdk.device.isMeshWifiDevice()

Return parameter

Name Type Description
isMeshWifiDevice boolean Whether it is a device that supports wireless networking

Request example

TYSdk.device.isMeshWifiDevice();

TYSdk.device.isShareDevice()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
isShareDevice boolean Whether it is a device that can be shared

Request example

TYSdk.device.isShareDevice();

TYSdk.device.isSigMeshDevice()

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
isSigMeshDevice boolean Whether it is a Bluetooth mesh device

Request example

TYSdk.device.isSigMeshDevice();

TYSdk.device.isWifiDevice()

Return parameter

Name Type Description
isWifiDevice boolean Whether it is a Wi-Fi device

Request example

TYSdk.device.isWifiDevice();

TYSdk.device.putDeviceData()

Request parameter

Name Type Description Required
dpState `{ dpCode: number string boolean }`

Request example

TYSdk.device.putDeviceData(dpState);

// Example: Send true to the switch of a product (dpCode is switch).

TYSdk.device.putDeviceData({ switch: true });

TYSdk.device.putLocalDpData()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
dpState `{ dpCode: number string boolean }`

Request example

/**
 * @desc Distribution of DPs in LAN
 * @param {Object} data - DP data
 */

TYSdk.device.putLocalDpData(dpState);

Mobile Methods

TYSdk.mobile.back()

Request example

/**
 * @desc Jump out of the panel container and return to the app list
 */

TYSdk.mobile.back();

TYSdk.mobile.bottomListDialog()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
itemList string[] List Yes
selected string An item selected in the list Yes
onConfirmed () => void Confirmation function Yes

Request example

/**
 * @desc Bottom dialog list
 */

TYSdk.mobile.bottomListDialog(itemList, selected, onConfirmed);
API

TYSdk.mobile.disablePopGesture()

Request example

/**
 * @desc Disable fullscreen pop gesture in iOS
 */

TYSdk.mobile.disablePopGesture();

TYSdk.mobile.enablePopGesture()

Request example

/**
 * @desc ios Enable fullscreen pop gesture in iOS
 */

TYSdk.mobile.enablePopGesture();

TYSdk.mobile.getMobileInfo()

Return parameter

Name Type Description
MobileInfo MobileInfo Get client information

Request example

/**
 * @desc Get client information, such as app version information, time zone, etc
 */

TYSdk.mobile.getMobileInfo();

TYSdk.mobile.getNetworkState()

Return parameter

Name Type Description
netWorkState `‘WIFI’ ‘GPRS’

Request example

TYSdk.mobile.getNetworkState();

TYSdk.mobile.hideLoading()

Request example

/**
 * @desc Hide reading status
 */

TYSdk.mobile.hideLoading();

TYSdk.mobile.is24Hour()

Return parameter

Name Type Description
is24Hour Promise<boolean> Whether it is the 24-hour clock

Request example

TYSdk.mobile.is24Hour()
.then(data => {
    console.log('data :>> ', data);
  })
  .catch(error => {
    console.log('error :>> ', error);
  });

TYSdk.mobile.jumpSubPage()

Request parameter

Name Type Description Required
uiIdParams { uiId: string } Secondary page item uiId Yes
pageParams object Passed attributes Yes

Request example

/**
 * @desc Jump to secondary page according to uiid
 */

TYSdk.mobile.jumpSubPage(uiIdParams: { uiId }, pageParams);

TYSdk.mobile.jumpTo()

Request parameter

Name Type Description Required
url string Set the URL jump function to jump to the mall, official website. If the short URL is configured with a parameter, you need to add the parameter, such as ${url}? homeId=123456 Yes

Request example

/**
 * @desc Jump to an existing scene that has not been unmounted. You can jump to the web page
 */

TYSdk.mobile.jumpTo(url);
Module URL Parameter Remark
Scene module sceneAction {"action":"sceneUiUpdate"} Scenario common actions, such as refreshing UI
createScene {"devid":"Device Id"} General creation scenario
createScene_allDevices None ZigBee scene switch jumps in and creates all device types
editScene {"sceneId":"Device Id"} General editing scenarios
createAuto {"devId":"Device Id","dpId":"dpId","dpValue":"dpValue","actionDisplay":"Action display name","actionExcutor":"Action type"} Sound and light alarm panel jump in, create automation, bring action data
createAutoWithCondition {"devId":"Device Id","dpId":"dpId","dpValue":"dpValue","operator":"Operator","exprDisplay":"Expression display name","entityType":"Condition type","extraInfo":"Conditional additional information"} Creating automation, carrying conditions
Family module tysh_house_manage None Family management page
tysh_room_manage { "homeId": "Room id" } Room management page
tysh_family_add None Add family page
tysh_family_setting { "homeId": "Room id" } Set family page
tysh_room_setting { "homeId": "Room id" } Set room page
tysh_family_add_member { "homeId": "Room id" } Add family member page
tysh_family_associate_member_rn {"memberId": "Member ID", "isAdmin": "Whether it is the administrator "} Jump to the associated member page
member_info {"memberId": "memberId", "role":"roleType", "homeId": "homeId"} Family member information
User center about None About us
user None User information page
ty_user_center None User center page
ty_user_setting None Setting page
browser { "url": "FAQ webpage URL" } Frequently asked questions
settingMoreService None Jump to more services
ty_mobile_bind None Bind the mobile phone number
Login module registernew None Register
tp_login None Login page
ty_auth_code_login {"countryCode": "Country code", "account": "Account"} Verification code login page
modifyPassword None Change password in login status
ty_forget_password {"countryCode": "Country code", "account": "Account"} Forget password
ty_signout None Logout
ty_anonymous_mode None Jump to experience mode
Distribution network module presentGatewayCategroy {"gwId": "Gateway Id"} The first version of ZigBee gateway panel with sub device routing
device_only_search_config_gw_sub {"gwId": "Gateway Id"} The beginning of new gateway panel distribution network sub equipment scanning distribution network routing
device_gw_sub_device_help_list {"gwId": "Gateway Id"} Sub device type list routing of sub equipment in new gateway panel
Homepage module ty_family_speech None Short URL of the voice assistant desktop shortcut
Feedback module ty_feedback { "key" : "Feedback key" } Fill in the feedback page
helpAndFeedBack None Feedback list page
Message center messageCenter None Message center page

TYSdk.mobile.mobileInfo

Note: 4.0 and above versions support this function.

Return parameter

Name Type Description
MobileInfo MobileInfo Get client information

Request example

console.log(TYSdk.mobile.mobileInfo);

TYSdk.mobile.showEditDialog()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
title string Title Yes
editString string Edit message content Yes
onConfirmed () => void Confirmation function Yes
onCanceled () => void Cancelation function Yes

Request example

/**
 * @desc Edit dialog box
 */

TYSdk.mobile.showEditDialog(title, editString, onConfirmed, onCanceled);
API

TYSdk.mobile.showLoading()

Request example

/**
 * @desc Show the reading status
 * Note: Displaying the dialog in the upper modal will cause lifecycle exception in iOS. 
 */

TYSdk.mobile.showLoading();

TYSdk.mobile.showPromptDialog()

Request parameter

Name Type Description Required
confirmText string Confirmation text Yes
cancelText string Cancelation text Yes
title string Dialog box title Yes
message string Message Yes
defaultValue string Default value Yes
onConfirmed () => void Confirmation function Yes
onCanceled () => void Cancelation function Yes

Request example

/**
 * @desc Lightweight prompt dialog box
 */

TYSdk.mobile.showPromptDialog(
  confirmText,
  cancelText,
  title,
  message,
  defaultValue,
  onConfirmed,
  onCanceled
);
API

TYSdk.mobile.simpleConfirmDialog()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
title string Title Yes
msg string Dialog box message Yes
onConfirmed () => void Confirmation function Yes
onCanceled () => void Cancelation function Yes

Request example

/**
 * @desc Simple confirmation dialog box
 */

TYSdk.mobile.simpleConfirmDialog(title, msg, onConfirmed, onCanceled);
API

TYSdk.mobile.simpleTipDialog()

Note: 4.0 and above versions support this function.

Request parameter

Name Type Description Required
msg string Dialog box message Yes
onConfirmed () => void Confirmation function Yes

Request example

/**
 * @desc Simple prompt box
 */

TYSdk.mobile.simpleTipDialog(msg, onConfirmed);
API

TYSdk.mobile.verSupported()

Return parameter

Name Type Description
verSupported boolean Is the app version supported

Request example

TYSdk.mobile.verSupported();

Native method

TYSdk.native.gotoDpAlarm()

Note: TYSdk.native.gotoDpAlarm does not support raw device function points (dpId).

Request parameter

Name Type Description Required
category string Timing type Yes
repeat number 0 indicates that selecting repeat is necessary, and 1 indicates that selecting repeat is unnecessary Yes
data data Need timing related DP information Yes

Request example

/**
 * @desc Jump to cloud timing page
 * @param {String} category - Custom timing type
 * @param {String | Number} dpId - Obtain the timing DP
 * @param {String } dpName - Displayed DP name
 * @param {Array} rangeKeys - DP value range
 * @param { Array } rangeValues - Displayed DP data range, and the message corresponds to rangeKeys
 */

const dpId = TYSdk.device.getDpIdByCode(dpCode);
const dpName = Strings.getDpLang(dpCode);
const category = "schedule";
TYSdk.native.gotoDpAlarm({
  category,
  repeat: 0, // 0 indicates that selecting repeat is necessary, and 1 indicates that selecting repeat is unnecessary
  data: [
    {
      dpId,
      dpName,
      selected: 0, //  Index of DP default value
      rangeKeys: [true, false],
      rangeValues: [dpValue1, dpValue2],
    },
  ],
});
APIAPI

TYSdk.native.showDeviceMenu()

Request example

/**
 * @desc Jump to device details
 */

TYNative.showDeviceMenu();

This section contains the following topics to help you quickly understand related concepts and how-to guides: