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

Shortcut Parser for Android

Last Updated on : 2021-07-05 07:48:42download

ShortcutParser serves as an extension SDK of Tuya IoT App SDK. It can be used to parse shortcut features of the device data model (DeviceBean) and the group data model (GroupBean). This accelerates the process to develop device or group shortcut features for your business.

Background information

Data points (DPs) are used to describe the features of Powered by Tuya devices. DP data is parsed, rendered, and operated on the clients to manage device status. You can develop device panels that support specified DPs based on Reactive Native. Then, users can control smart devices with the device panels.

To implement shortcut features, Tuya provides flags to display and control DPs without entering device panels. In common cases, the most important DPs are flagged and displayed on the list of devices. This way, users can touch the shortcut flags to easily get device status or control devices without the need to enter device panels.

Preparation

The SDK depends on TuyaHomeKitSDK 3.11.0 or later. Add the following dependency to the module file build.gradle:

implementation 'com.tuya.smart:tuyasmart-shortcutparser:0.0.1'

Add the following maven source to repositories of the file build.gradle in the root directory:

maven {
  url "https://maven-other.tuya.com/repository/maven-releases/"
}

API operations

The core of the SDK provides the capabilities to parse shortcut DPs for devices and groups. The following table describes the API operations that are encapsulated in the SDK.

Class Description
IShortcutParserManager Manages the shortcut parsers.
IClientParser Parses DP data on clients.
IDpControl Provides basic control with DPs.
IBoolDpControl Provides shortcut control with Boolean DPs.
IEnumDpControl Provides shortcut control with enumeration DPs.
INumDpControl Provides shortcut control with value DPs.
IDpStatus Provides shortcut control with status DPs.

The following figure shows the architecture of these API operations.

Shortcut Parser for Android

IShortcutParserManager

API description

public interface IShortcutParserManager {
	/**
	* Returns device parsing data.
	*
	* @param deviceBean
	* @return
	*/
	IClientParser getDeviceParseData(DeviceBean deviceBean);

	/**
	* Returns group parsing data.
	*
	* @param groupBean
	* @return
	*/
	IClientParser getGroupParseData(GroupBean groupBean, ProductBean productBean);
}

Example

// Initializes the SDK.
IShortcutParserManager mIShortcutParserManager = new ShortcutParserManager();

Shortcut control

Shortcut control can be used with readable and writable DPs to implement device functionality. You can configure the DPs for shortcut control on the Tuya IoT Platform. For more information, see Enable Toggle.

Based on these configurations, DeviceBean or GroupBean from the SDK contains the specified shortcut control DPs. This allows you to use the SDK to develop shortcut control features.

Shortcut control DPs are classified into device switch DPs and generic shortcut DPs.

Shortcut switches

Shortcut switches are the switch DPs for smart devices. A DP that is flagged as a device shortcut switch DP indicates the power switch of the device.

The API operation IClientParserBean of IShortcutParserManager includes the following shortcut switch data:

  • Shortcut switch status

    enum SHORTCUT_SWITCH_STATUS{
    	// Shortcut switch not configured.
    	SWITCH_NONE(0),
    	// Shortcut switch enabled.
    	SWITCH_ON(1),
    	// Shortcut switch disabled.
    	SWITCH_OFF(2);
    
    	private int status;
    
    	SHORTCUT_SWITCH_STATUS(int status) {
    		this.status = status;
    	}
    
    	public int getStatus() {
    		return status;
    	}
    }
    
  • Get the shortcut switch status

    API description

    /**
    * Returns the shortcut switch status.
    * @return An enumeration value of status.
    */
    SHORTCUT_SWITCH_STATUS getSwitchStatus();
    

    Example

    IClientParser mClientParser = mShortcutParserManager.updateDeviceParseData(mDev);
    Log.d(TAG,mClientParser.getSwitchStatus());
    
  • Get shortcut switch operations

    /**
    * Returns parsing data of shortcut switch DPs.
    * @return Parses shortcut switch DPs.
    */
    IBoolDpControl getSwitchDpParseBean();
    

Generic shortcut DPs

You can get a list of shortcut DPs by using IClientParserBean.

/**
 * Returns a list of shortcut DPs.
 * @return
 */
List<IDpControl> getDpShortcutControlList();

The returned shortcut DPs support enumeration, value, and Boolean types. Each API operation provides data that can be parsed. For more information, see the annotations of each API operation.

Data updates

In most cases, the data of dps is updated after device control. You can call the data update operation of IClientParserBean to get the latest status.

API description

/**
 * Parses updates of device or group status.
 * @param dps The values of device or group DPs.
 * @param dpName The names of device or group DPs.
 */
void update(Map<String, Object> dps, Map<String, String> dpName);

Example

// Returns the latest cached data from the SDK.
mDev = TuyaHomeSdk.getDataInstance().getDeviceBean(devId);
// Updates the DPs and DP names.
mClientParserBean.update(mDev.getDps(),mDev.getDpName());

Shortcut status

The DPs with the shortcut flags can be used for sensor devices to indicate read-only status of the devices. This feature is not supported on the Tuya IoT Platform when you configure a product. You can submit a ticket to request technical support.

IClientParserBean provides the API operation to return a list of device or group shortcut DP status.

API description

/**
 * Returns a list of device or group shortcut DP status.
 * @return
 */
List<IDpStatus> getDpShortcutStatusList();

For more information about the capabilities to parse the shortcut DP status, see the annotations of the API operation.