]> git.basschouten.com Git - openhab-addons.git/blob
d92a61aed29c76b35f74d3b86ede798364d551b8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.HSBK;
21 import org.openhab.binding.lifx.internal.fields.HSBKField;
22 import org.openhab.binding.lifx.internal.fields.UInt32Field;
23 import org.openhab.binding.lifx.internal.fields.UInt8Field;
24
25 /**
26  * @author Wouter Born - Initial contribution
27  */
28 public class SetColorZonesRequest extends Packet {
29
30     public static final int TYPE = 0x1F5;
31
32     public static final Field<Integer> FIELD_START_INDEX = new UInt8Field();
33     public static final Field<Integer> FIELD_END_INDEX = new UInt8Field();
34     public static final HSBKField FIELD_COLOR = new HSBKField();
35     public static final Field<Long> FIELD_FADE_TIME = new UInt32Field().little();
36     public static final Field<Integer> FIELD_APPLY = new UInt8Field();
37
38     private int startIndex = MIN_ZONE_INDEX;
39     private int endIndex = MAX_ZONE_INDEX;
40     private HSBK color;
41     private long fadeTime;
42     private ApplicationRequest apply;
43
44     public HSBK getColor() {
45         return color;
46     }
47
48     public int getHue() {
49         return color.getHue();
50     }
51
52     public int getSaturation() {
53         return color.getSaturation();
54     }
55
56     public int getBrightness() {
57         return color.getBrightness();
58     }
59
60     public int getKelvin() {
61         return color.getKelvin();
62     }
63
64     public long getFadeTime() {
65         return fadeTime;
66     }
67
68     public ApplicationRequest getApply() {
69         return apply;
70     }
71
72     public SetColorZonesRequest() {
73         setTagged(false);
74         setAddressable(true);
75         setResponseRequired(true);
76     }
77
78     public SetColorZonesRequest(HSBK color, long fadeTime, ApplicationRequest apply) {
79         this(MIN_ZONE_INDEX, MAX_ZONE_INDEX, color, fadeTime, apply);
80     }
81
82     public SetColorZonesRequest(int index, HSBK color, long fadeTime, ApplicationRequest apply) {
83         this(index, index, color, fadeTime, apply);
84     }
85
86     public SetColorZonesRequest(int startIndex, int endIndex, HSBK color, long fadeTime, ApplicationRequest apply) {
87         this();
88         this.startIndex = startIndex;
89         this.endIndex = endIndex;
90         this.color = color;
91         this.fadeTime = fadeTime;
92         this.apply = apply;
93     }
94
95     @Override
96     public int packetType() {
97         return TYPE;
98     }
99
100     @Override
101     protected int packetLength() {
102         return 15;
103     }
104
105     @Override
106     protected void parsePacket(ByteBuffer bytes) {
107         startIndex = FIELD_START_INDEX.value(bytes);
108         endIndex = FIELD_END_INDEX.value(bytes);
109         color = FIELD_COLOR.value(bytes);
110         fadeTime = FIELD_FADE_TIME.value(bytes);
111         apply = ApplicationRequest.fromValue(FIELD_APPLY.value(bytes));
112     }
113
114     @Override
115     protected ByteBuffer packetBytes() {
116         return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
117                 .put(FIELD_END_INDEX.bytes(endIndex)).put(FIELD_COLOR.bytes(color)).put(FIELD_FADE_TIME.bytes(fadeTime))
118                 .put(FIELD_APPLY.bytes(apply.getValue()));
119     }
120
121     @Override
122     public int[] expectedResponses() {
123         return new int[] {};
124     }
125 }