]> git.basschouten.com Git - openhab-addons.git/blob
fbdc0ddec7c86a1abbb52a34909174a993ecff3c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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         setTagged(false);
37         setAddressable(true);
38         setResponseRequired(true);
39     }
40
41     public GetColorZonesRequest(int index) {
42         this(index, index);
43     }
44
45     public GetColorZonesRequest(int startIndex, int endIndex) {
46         this();
47         this.startIndex = startIndex;
48         this.endIndex = endIndex;
49     }
50
51     public int getStartIndex() {
52         return startIndex;
53     }
54
55     public int getEndIndex() {
56         return endIndex;
57     }
58
59     @Override
60     public int packetType() {
61         return TYPE;
62     }
63
64     @Override
65     protected int packetLength() {
66         return 2;
67     }
68
69     @Override
70     protected void parsePacket(ByteBuffer bytes) {
71         startIndex = FIELD_START_INDEX.value(bytes);
72         endIndex = FIELD_END_INDEX.value(bytes);
73     }
74
75     @Override
76     protected ByteBuffer packetBytes() {
77         return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
78                 .put(FIELD_END_INDEX.bytes(endIndex));
79     }
80
81     @Override
82     public int[] expectedResponses() {
83         return new int[] { StateMultiZoneResponse.TYPE, StateZoneResponse.TYPE };
84     }
85 }