---
name: "HSColourSetTransformer"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.0.0" }
title: "HSColourSetTransformer"
summary: "HSColourSetTransformer is used to parse the lighting `hs_color_set` DP and provides parsing and formatting for HS colors."
questions:
  - "What is HSColourSetTransformer used for?"
  - "How does HSColourSetTransformer parse HS colors?"
  - "What are the input and output of HSColourSetTransformer?"
  - "What are the transformation rules of HSColourSetTransformer?"
---

## HSColourSetTransformer

> [VERSION] @ray-js/panel-sdk >= 1.0.0

> 💡 For the HS color-setting DP (e.g., hs_color_set) of Zigbee lighting products, performs two-way conversion between front-end hue (0–360)/saturation (0–1000) and the device protocol's 2-byte (range 0–254) hexadecimal format. Note: This converter maps ranges for hue and saturation (hue: 0–360 <-> 0–254, saturation: 0–1000 <-> 0–254).

### Description

HS color setting protocol converter for bidirectional conversion between HS color values and the Zigbee DP protocol format

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `uuid` | `string` | No | DP identifier, defaults to 'hs_color_set' |
| `defaultValue` | `TColorData` | No | Default HS value, returned when parsing fails |

### Return Value

Type: `HSColourSetTransformer`

HSColourSetTransformer instance

#### Methods

| Method | Description |
| --- | --- |
| `parser` | Parse a DP hexadecimal string into an HS color value object |
| `formatter` | Format an HS color value object into a DP hexadecimal string |

### Referenced Types

##### `type` TColorData

| Property | Type | Description |
| --- | --- | --- |
| `hue` | `number` | Hue |
| `saturation` | `number` | Saturation |
| `value` | `number` | Brightness |


### Examples

#### Example

```ts
import { HSColourTransformer } from '@ray-js/panel-sdk';

const transformer = new HSColourTransformer();
// Parse a DP string into an HS object
const hs = transformer.parser('fefe');
// => { hue: 360, saturation: 1000 }

// Format an HS object into a DP string
const dpStr = transformer.formatter({ hue: 180, saturation: 500 });
```
