Lighting Conversion Tool

Last Updated on : 2023-12-18 06:19:30download

Installation

yarn add @tuya/tuya-panel-lamp-sdk

Use

import { Utils } from '@tuya/tuya-panel-lamp-sdk';

const { to16, formatPercent, randomHsv, randomSceneColor, getStrLengthByByte } = Utils;

Use cases

Method Feature Parameter Remarks
to16 Converts a decimal number to a hexadecimal number. (value: number, length = 2) The value of length defaults to 2 to represent one byte.
formatPercent The calculation in percent. (value: number, { min = 0, max =1000, minPercent = 0 }: PercentOption = {}) None
randomHsv Returns a random hue, saturation, and value (HSV) color. (isValueRandom: boolean = false) None
randomSceneColor Returns a random scene color. (isGetColour: boolean = true) None
getStrLengthByByte Returns the byte length of a string. (value: string) None

Example

import { Utils } from '@tuya/tuya-panel-lamp-sdk';

const { to16, formatPercent, randomHsv, randomSceneColor, getStrLengthByByte } = Utils;

to16(100, 2); // 64

formatPercent(100); // 10 
formatPercent(100, { max = 100 }); // 100
formatPercent(100, { minPercent = 1 }); // 100


randomHsv(); //  { hue: 22, saturation: 340, value: 20}
randomHsv(true); //  { hue: 232, saturation: 30, value: 1000 // `value`: a fixed value.}

randomSceneColor(); 
/* { isColour: false,
       temperature:222, // A random number.
       brightness: 123, // A random number.
       hue: 0,
       saturation: 0,
       value: 10,
}*/

randomSceneColor(true); 
/* {
       isColour: true,
       temperature:0, 
       brightness: 10, 
       hue: 223, // A random number.
       saturation: 453, // A random number.
       value: 20, // A random number.
}*/
        

getStrLengthByByte('12dd'); //  4
getStrLengthByByte('Text 123'); // 11