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.Field;
18 import org.openhab.binding.lifx.internal.fields.HSBK;
19 import org.openhab.binding.lifx.internal.fields.HSBKField;
20 import org.openhab.binding.lifx.internal.fields.StringField;
21 import org.openhab.binding.lifx.internal.fields.UInt16Field;
22 import org.openhab.binding.lifx.internal.fields.UInt64Field;
25 * @author Tim Buckley - Initial contribution
26 * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
28 public class StateResponse extends Packet {
30 public static final int TYPE = 0x6B;
32 public static final HSBKField FIELD_COLOR = new HSBKField();
33 public static final Field<Integer> FIELD_DIM = new UInt16Field().little();
34 public static final Field<Integer> FIELD_POWER = new UInt16Field();
35 public static final Field<String> FIELD_LABEL = new StringField(32);
36 public static final Field<Long> FIELD_TAGS = new UInt64Field();
40 private PowerState power;
45 public String toString() {
46 return color.toString("color") + ", dim=" + dim + ", power=" + power + ", label=" + label;
49 public HSBK getColor() {
57 public PowerState getPower() {
61 public String getLabel() {
65 public long getTags() {
70 public int packetType() {
75 protected int packetLength() {
80 protected void parsePacket(ByteBuffer bytes) {
81 color = FIELD_COLOR.value(bytes);
82 dim = FIELD_DIM.value(bytes);
83 power = PowerState.fromValue(FIELD_POWER.value(bytes));
84 label = FIELD_LABEL.value(bytes);
85 tags = FIELD_TAGS.value(bytes);
89 protected ByteBuffer packetBytes() {
90 return ByteBuffer.allocate(packetLength()).put(FIELD_COLOR.bytes(color)).put(FIELD_DIM.bytes(dim))
91 .put(FIELD_POWER.bytes(power.getValue())).put(FIELD_LABEL.bytes(label)).put(FIELD_TAGS.bytes(tags));
95 public int[] expectedResponses() {