]> git.basschouten.com Git - openhab-addons.git/blob
d42e1f55fd1986e636e0575bd4bfdf04b83dca9b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lifx.internal.dto;
14
15 import java.nio.ByteBuffer;
16
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;
21
22 /**
23  * @author Wouter Born - Initial contribution
24  */
25 public class StateZoneResponse extends Packet {
26
27     public static final int TYPE = 0x1F7;
28
29     public static final Field<Integer> FIELD_COUNT = new UInt8Field();
30     public static final Field<Integer> FIELD_INDEX = new UInt8Field();
31     public static final HSBKField FIELD_COLOR = new HSBKField();
32
33     private int count;
34     private int index;
35     private HSBK color;
36
37     @Override
38     public String toString() {
39         return "count=" + count + ", index=" + index + ", " + color.toString("color");
40     }
41
42     public int getCount() {
43         return count;
44     }
45
46     public int getIndex() {
47         return index;
48     }
49
50     public HSBK getColor() {
51         return color;
52     }
53
54     @Override
55     public int packetType() {
56         return TYPE;
57     }
58
59     @Override
60     protected int packetLength() {
61         return 10;
62     }
63
64     @Override
65     protected void parsePacket(ByteBuffer bytes) {
66         count = FIELD_COUNT.value(bytes);
67         index = FIELD_INDEX.value(bytes);
68         color = FIELD_COLOR.value(bytes);
69     }
70
71     @Override
72     protected ByteBuffer packetBytes() {
73         return ByteBuffer.allocate(packetLength()).put(FIELD_COUNT.bytes(count)).put(FIELD_INDEX.bytes(index))
74                 .put(FIELD_COLOR.bytes(color));
75     }
76
77     @Override
78     public int[] expectedResponses() {
79         return new int[] {};
80     }
81 }