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 java.nio.ByteBuffer;
17 import org.openhab.binding.lifx.internal.fields.ByteField;
18 import org.openhab.binding.lifx.internal.fields.Field;
19 import org.openhab.binding.lifx.internal.fields.HSBK;
20 import org.openhab.binding.lifx.internal.fields.HSBKField;
21 import org.openhab.binding.lifx.internal.fields.UInt32Field;
24 * @author Tim Buckley - Initial contribution
25 * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
27 public class SetColorRequest extends Packet {
29 public static final int TYPE = 0x66;
31 public static final Field<ByteBuffer> FIELD_STREAM = new ByteField(1);
32 public static final HSBKField FIELD_COLOR = new HSBKField();
33 public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
35 private ByteBuffer stream;
38 private long fadeTime;
40 public ByteBuffer getStream() {
44 public HSBK getColor() {
48 public long getFadeTime() {
52 public SetColorRequest() {
53 stream = ByteBuffer.allocate(1);
55 setResponseRequired(true);
58 public SetColorRequest(HSBK color, long fadeTime) {
61 this.fadeTime = fadeTime;
65 public int packetType() {
70 protected int packetLength() {
75 protected void parsePacket(ByteBuffer bytes) {
76 stream = FIELD_STREAM.value(bytes);
77 color = FIELD_COLOR.value(bytes);
78 fadeTime = FIELD_FADE_TIME.value(bytes);
82 protected ByteBuffer packetBytes() {
83 return ByteBuffer.allocate(packetLength()).put(FIELD_STREAM.bytes(stream)).put(FIELD_COLOR.bytes(color))
84 .put(FIELD_FADE_TIME.bytes(fadeTime));
88 public int[] expectedResponses() {
89 return new int[] { StateResponse.TYPE };