2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal.dto;
15 import static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
17 import java.nio.ByteBuffer;
19 import org.openhab.binding.lifx.internal.fields.Field;
20 import org.openhab.binding.lifx.internal.fields.HSBK;
21 import org.openhab.binding.lifx.internal.fields.HSBKField;
22 import org.openhab.binding.lifx.internal.fields.UInt32Field;
23 import org.openhab.binding.lifx.internal.fields.UInt8Field;
26 * @author Wouter Born - Initial contribution
28 public class SetColorZonesRequest extends Packet {
30 public static final int TYPE = 0x1F5;
32 public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
33 public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
34 public static final HSBKField FIELD_COLOR = new HSBKField();
35 public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
36 public static final Field<Integer> FIELD_APPLY = new UInt8Field();
38 private int startIndex = MIN_ZONE_INDEX;
39 private int endIndex = MAX_ZONE_INDEX;
41 private long fadeTime;
42 private ApplicationRequest apply;
44 public HSBK getColor() {
49 return color.getHue();
52 public int getSaturation() {
53 return color.getSaturation();
56 public int getBrightness() {
57 return color.getBrightness();
60 public int getKelvin() {
61 return color.getKelvin();
64 public long getFadeTime() {
68 public ApplicationRequest getApply() {
72 public SetColorZonesRequest() {
74 setResponseRequired(true);
77 public SetColorZonesRequest(HSBK color, long fadeTime, ApplicationRequest apply) {
78 this(MIN_ZONE_INDEX, MAX_ZONE_INDEX, color, fadeTime, apply);
81 public SetColorZonesRequest(int index, HSBK color, long fadeTime, ApplicationRequest apply) {
82 this(index, index, color, fadeTime, apply);
85 public SetColorZonesRequest(int startIndex, int endIndex, HSBK color, long fadeTime, ApplicationRequest apply) {
87 this.startIndex = startIndex;
88 this.endIndex = endIndex;
90 this.fadeTime = fadeTime;
95 public int packetType() {
100 protected int packetLength() {
105 protected void parsePacket(ByteBuffer bytes) {
106 startIndex = FIELD_START_INDEX.value(bytes);
107 endIndex = FIELD_END_INDEX.value(bytes);
108 color = FIELD_COLOR.value(bytes);
109 fadeTime = FIELD_FADE_TIME.value(bytes);
110 apply = ApplicationRequest.fromValue(FIELD_APPLY.value(bytes));
114 protected ByteBuffer packetBytes() {
115 return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
116 .put(FIELD_END_INDEX.bytes(endIndex)).put(FIELD_COLOR.bytes(color)).put(FIELD_FADE_TIME.bytes(fadeTime))
117 .put(FIELD_APPLY.bytes(apply.getValue()));
121 public int[] expectedResponses() {