]> git.basschouten.com Git - openhab-addons.git/blob
087a74dd71779d4690c583b0942663ffbf5062c3
[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 static org.openhab.binding.lifx.internal.LifxBindingConstants.*;
16
17 import java.nio.ByteBuffer;
18
19 import org.openhab.binding.lifx.internal.fields.Field;
20 import org.openhab.binding.lifx.internal.fields.UInt8Field;
21
22 /**
23  * @author Wouter Born - Initial contribution
24  */
25 public class GetColorZonesRequest extends Packet {
26
27     public static final int TYPE = 0x1F6;
28
29     public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
30     public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
31
32     private int startIndex = MIN_ZONE_INDEX;
33     private int endIndex = MAX_ZONE_INDEX;
34
35     public GetColorZonesRequest() {
36         setAddressable(true);
37         setResponseRequired(true);
38     }
39
40     public GetColorZonesRequest(int index) {
41         this(index, index);
42     }
43
44     public GetColorZonesRequest(int startIndex, int endIndex) {
45         this();
46         this.startIndex = startIndex;
47         this.endIndex = endIndex;
48     }
49
50     public int getStartIndex() {
51         return startIndex;
52     }
53
54     public int getEndIndex() {
55         return endIndex;
56     }
57
58     @Override
59     public int packetType() {
60         return TYPE;
61     }
62
63     @Override
64     protected int packetLength() {
65         return 2;
66     }
67
68     @Override
69     protected void parsePacket(ByteBuffer bytes) {
70         startIndex = FIELD_START_INDEX.value(bytes);
71         endIndex = FIELD_END_INDEX.value(bytes);
72     }
73
74     @Override
75     protected ByteBuffer packetBytes() {
76         return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
77                 .put(FIELD_END_INDEX.bytes(endIndex));
78     }
79
80     @Override
81     public int[] expectedResponses() {
82         return new int[] { StateMultiZoneResponse.TYPE, StateZoneResponse.TYPE };
83     }
84 }