Colored Light Protocol

Last Updated on : 2021-12-16 03:11:51download

Overview

ColourFormatter is a class method used to parse and reversely parse data points (DPs) for colored lighting. The parse method can be called to parse the hexadecimal strings reported by firmware into data structures required by device panels. The format method can be called to reversely parse object data into hexadecimal strings in line with generic protocols for colored light.

API methods

parse

Type Required Description
String Yes The hexadecimal string.

format

Type Required Description
Object Yes The object of the IColour class.
declare interface IColour {
  hue?: number;
  saturation: number;
  value: number;
}

Example

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

const { SupportUtils } = Utils;
const { ColourFormatter } = Formatter;

const d = new ColourFormatter()

d.parse('000003e803e8')

d.format({
  hue: 0, 
  saturation: 1000, 
  value: 1000
});