Lighting Product Protocol Utilities

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

Installation

$ npm install @tuya/tuya-panel-protocols
// or
$ yarn add @tuya/tuya-panel-protocols

Color conversion protocols

HSV to HHHHSSSSVVVV

Action

encodeColorData

Description

Converts the hue, saturation, and value (HSV) color data from the decimal format to the hexadecimal format of hhhhssssvvvv.

Request parameter

Parameter Data type Description Required
h number The value of hue. Valid values: [0, 360]. Yes
s number The value of saturation. Valid values: [ 0, 1000]. Yes
v number The value of value. Valid values: [ 0, 1000]. Yes

Return parameter

Parameter Data type Description
hsv string The HSV color data in the hexadecimal format.

Sample request

import { lampProtocol } from '@tuya/tuya-panel-protocols';

const { ColorProtocol } = lampProtocol;
ColorProtocol.encodeColorData(h, s, v);

// Example
ColorProtocol.encodeColorData(360, 1000, 1000)

Sample response

'016803e803e8'

HHHHSSSSVVVV to HSV

Action

decodeColorData

Description

Converts the hue, saturation, and value (HSV) color data from the hexadecimal format of hhhhssssvvvv to the decimal format.

Request parameter

Parameter Data type Description Required
hsv string The HSV color data in the hexadecimal format. Yes

Return parameter

Parameter Data type Description
result number[] [ h: hue, s: saturation, v: value]

Sample request

import { lampProtocol } from '@tuya/tuya-panel-protocols';

const { ColorProtocol } = lampProtocol;
ColorProtocol.decodeColorData(hsv);

// Example
ColorProtocol.decodeColorData('016803e803e8')

Sample response

[360, 1000, 1000]