]> git.basschouten.com Git - openhab-addons.git/blob
b376b8521d5fae16458c60349fbf05b704617f7e
[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.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         setAddressable(true);
74         setResponseRequired(true);
75     }
76
77     public SetColorZonesRequest(HSBK color, long fadeTime, ApplicationRequest apply) {
78         this(MIN_ZONE_INDEX, MAX_ZONE_INDEX, color, fadeTime, apply);
79     }
80
81     public SetColorZonesRequest(int index, HSBK color, long fadeTime, ApplicationRequest apply) {
82         this(index, index, color, fadeTime, apply);
83     }
84
85     public SetColorZonesRequest(int startIndex, int endIndex, HSBK color, long fadeTime, ApplicationRequest apply) {
86         this();
87         this.startIndex = startIndex;
88         this.endIndex = endIndex;
89         this.color = color;
90         this.fadeTime = fadeTime;
91         this.apply = apply;
92     }
93
94     @Override
95     public int packetType() {
96         return TYPE;
97     }
98
99     @Override
100     protected int packetLength() {
101         return 15;
102     }
103
104     @Override
105     protected void parsePacket(ByteBuffer bytes) {
106         startIndex = FIELD_START_INDEX.value(bytes);
107         endIndex = FIELD_END_INDEX.value(bytes);
108         color = FIELD_COLOR.value(bytes);
109         fadeTime = FIELD_FADE_TIME.value(bytes);
110         apply = ApplicationRequest.fromValue(FIELD_APPLY.value(bytes));
111     }
112
113     @Override
114     protected ByteBuffer packetBytes() {
115         return ByteBuffer.allocate(packetLength()).put(FIELD_START_INDEX.bytes(startIndex))
116                 .put(FIELD_END_INDEX.bytes(endIndex)).put(FIELD_COLOR.bytes(color)).put(FIELD_FADE_TIME.bytes(fadeTime))
117                 .put(FIELD_APPLY.bytes(apply.getValue()));
118     }
119
120     @Override
121     public int[] expectedResponses() {
122         return new int[] {};
123     }
124 }