Biorhythm Protocol

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

Overview

rhythmFormatter is a class method used to parse and reversely parse data points (DPs) for lighting biorhythm. 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 biorhythm.

API methods

parse

Type Required Description
String Yes The hexadecimal string.

format

Type Required Description
Object Yes The object of the IRhythmData class.
declare interface IRhythmData {
  version: number;
  power: boolean;
  mode: number;
  weeks: number[];
  number: number;
  rhythms: IRhythmItem[];
  key?: number;
}

declare interface IRhythmItem {
  power: boolean,
   hour: number,
   minute: number,
   hue: number,
   saturation: number,
   value: number,
   brightness: number,
   temperature: number,
}

Example

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

const d = new RhythmFormatter(null,null,SupportUtils.isSupportTemp())

d.parse('0000007f0601060000000000006401061e000000006432010b1e00000000646401110000000000463201141e000000004632011500000000000000');

d.format({
  version: 0,
  power: false,
  mode: 0,
  weeks: [1, 1, 1, 1, 1, 1, 1, 0],
  number: 6,
  rhythms: [
    {
      power: true,
      hour: 6,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 0,
      temperature: 100,
    },
    {
      power: true,
      hour: 6,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 100,
      temperature: 50,
    },
    {
      power: true,
      hour: 11,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 100,
      temperature: 100,
    },
    {
      power: true,
      hour: 17,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 70,
      temperature: 50,
    },
    {
      power: true,
      hour: 20,
      minute: 30,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 70,
      temperature: 50,
    },
    {
      power: true,
      hour: 21,
      minute: 0,
      hue: 0,
      saturation: 0,
      value: 0,
      brightness: 0,
      temperature: 0,
    },
  ],
});