npm package: @ray-js/play-cool-sync-utils
Description: 照明酷玩吧功能页工具包
Latest version: 1.0.0

[简体中文](./README-zh_CN.md) | English

# @ray-js/play-cool-sync-utils

[![latest](https://img.shields.io/npm/v/@ray-js/play-cool-sync-utils/latest.svg)](https://www.npmjs.com/package/@ray-js/play-cool-sync-utils) [![download](https://img.shields.io/npm/dt/@ray-js/play-cool-sync-utils.svg)](https://www.npmjs.com/package/@ray-js/play-cool-sync-utils)

> Lighting Cool Play Functional Page Toolkit

## Installation

```sh
$ npm install @ray-js/play-cool-sync-utils
// Or
$ yarn add @ray-js/play-cool-sync-utils
```

## Development

```sh
# Real-time compilation of Demo code
yarn start:tuya
```

## Usage

1. Colorful

```ts
import {
  navigateToPlayCoolFunctional,
  clearPlayCoolFunctionalData,
} from '@ray-js/play-cool-sync-utils';

// deviceId Single device id, details are in the table above
// groupId Group id, details are in the table above
const jumpUrl = `functional://rayPlayCoolFunctional/home?deviceId=${deviceId || ''}&groupId=${
  groupId || ''
}&type=C`;

// Jump
navigateToPlayCoolSyncFunctional(jumpUrl);
```

2. Full Color

```ts
const jumpUrl = `functional://rayPlayCoolFunctional/home?deviceId=${deviceId || ''}&groupId=${
  groupId || ''
}&type=C`;

const data = {
  lightNum: '5', // 5-channel light, required for full color interface
  dpCode: 'scene_data', // Full color dp
};

// Jump
navigateToPlayCoolFunctional(jumpUrl, data);

// Clear data after returning to the current applet
clearPlayCoolFunctionalData(url);
```

3. Multi-device Control

```ts
import {
  navigateToPlayCoolFunctional,
  clearPlayCoolFunctionalData,
} from '@ray-js/play-cool-sync-utils';

const jumpUrl = `functional://rayPlayCoolFunctional/home?deviceId=${deviceId || ''}&groupId=${
  groupId || ''
}&type=C`;

const data = {
  deviceIds: 'dwadwadawdwa,dbwjkadbjwka,ndwadwabdaw', // Device list, separated by comma
  lightNum: '5,4,5', // Number of channels per device, separated by comma
};

// Jump
navigateToPlayCoolFunctional(jumpUrl, data);

// Clear data after returning to the current applet
clearPlayCoolFunctionalData(url);
```

## API

| Method Name                  | Parameter Description                   | Type                                                              |
| ---------------------------- | --------------------------------------- | ----------------------------------------------------------------- |
| presetPlayCoolFunctionalData | Store functional page data with Promise | `(url: string, data: PlayCoolFunctionalData) => Promise<boolean>` |
| clearPlayCoolFunctionalData  | Clear functional page data              | `(url: string) => Promise<boolean>`                               |
| navigateToPlayCoolFunctional | Jump to functional page                 | `(url: string, data?: PlayCoolFunctionalData) => void`            |

### PlayCoolFunctionalData

| Parameter  | Description                                                                                                                                                                                                                                                                 | Type         | Default | Required |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------- | -------- |
| groupId    | Group ID. If the address already has the parameter added, it can be omitted. When both groupId and deviceId are passed, groupId takes precedence.                                                                                                                           | `string`     | -       | Optional |
| deviceId   | Single Device ID. If the address already has the parameter added, it can be omitted. When both groupId and deviceId are passed, groupId takes precedence.                                                                                                                   | `string`     | -       | Optional |
| deviceIds  | Device list separated by commas                                                                                                                                                                                                                                             | `string`     | -       | Optional |
| dpCode     | Send DP name                                                                                                                                                                                                                                                                | `string`     | -       | Optional |
| lightNum   | Number of light strips                                                                                                                                                                                                                                                      | `string`     | -       | Optional |
| type       | Protocol. Can control multiple devices when equal to C. Multiple device control requires passing deviceIds                                                                                                                                                                  | `'C' \| 'B'` | -       | Optional |
| parserType | If using the new version of the scenario library, i.e., raw type with base64 format data, and string type with hex format data, you need to configure parserType as standard (which is standard mode, default is non-standard mode to be compatible with previous projects) | `'standard'` | -       | Optional |