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.UInt8Field;
23 * @author Wouter Born - Initial contribution
25 public class StateMultiZoneResponse extends Packet {
27 public static final int TYPE = 0x1FA;
28 public static final int ZONES = 8;
30 public static final Field<Integer> FIELD_COUNT = new UInt8Field();
31 public static final Field<Integer> FIELD_INDEX = new UInt8Field();
32 public static final HSBKField FIELD_COLOR = new HSBKField();
36 private HSBK[] colors = new HSBK[ZONES];
39 public String toString() {
40 StringBuilder sb = new StringBuilder();
43 sb.append(", index=");
46 for (int i = 0; i < ZONES; i++) {
48 sb.append(colors[i].toString("color[" + i + "]"));
54 public int getCount() {
58 public int getIndex() {
62 public HSBK[] getColors() {
67 public int packetType() {
72 protected int packetLength() {
77 protected void parsePacket(ByteBuffer bytes) {
78 count = FIELD_COUNT.value(bytes);
79 index = FIELD_INDEX.value(bytes);
80 for (int i = 0; i < ZONES; i++) {
81 colors[i] = FIELD_COLOR.value(bytes);
86 protected ByteBuffer packetBytes() {
87 ByteBuffer bb = ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index));
88 for (int i = 0; i < ZONES; i++) {
89 bb.put(FIELD_COLOR.bytes(colors[i]));
95 public int[] expectedResponses() {