]> git.basschouten.com Git - openhab-addons.git/blob
cabbee8336177331556d7e3622de2f4091c6cdbc
[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.tplinksmarthome.internal.model;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.OnOffType;
19
20 import com.google.gson.annotations.Expose;
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * Data class for setting the TP-Link Smart Light Strip state and retrieving the result.
25  *
26  * @author Hilbrand Bouwkamp - Initial contribution
27  */
28 public class SetLightState implements HasErrorResponse {
29
30     private static final int GROUPS_INDEX_HUE = 2;
31     private static final int GROUPS_INDEX_SATURATION = 3;
32     private static final int GROUPS_INDEX_BRIGHTNESS = 4;
33     private static final int GROUPS_INDEX_COLOR_TEMPERATURE = 5;
34
35     public static class ColorTemperature extends LightOnOff {
36         @Expose(deserialize = false)
37         private int colorTemp;
38         @Expose(deserialize = false)
39         private int hue = 0;
40         @Expose(deserialize = false)
41         private int saturation = 0;
42
43         public void setColorTemp(final int colorTemperature) {
44             this.colorTemp = colorTemperature;
45         }
46     }
47
48     public static class Color extends Brightness {
49         @Expose(deserialize = false)
50         private int colorTemp;
51         @Expose(deserialize = false)
52         private int hue;
53         @Expose(deserialize = false)
54         private int saturation;
55
56         public void setHue(final int hue) {
57             this.hue = hue;
58         }
59
60         public void setSaturation(final int saturation) {
61             this.saturation = saturation;
62         }
63     }
64
65     public static class Brightness extends LightOnOff {
66         @Expose(deserialize = false)
67         private int brightness;
68
69         public void setBrightness(final int brightness) {
70             this.brightness = brightness;
71         }
72     }
73
74     public static class LightOnOff extends ErrorResponse {
75         @Expose
76         private int onOff;
77         @Expose(serialize = false)
78         private String mode;
79         @Expose(deserialize = false)
80         private int transition;
81         /**
82          * groups contain status: [[0,31,0,0,73,5275]]
83          * [?,?,hue,saturation,brightness,color_temp]
84          */
85         @Expose(serialize = false)
86         protected int[][] groups;
87
88         public OnOffType getOnOff() {
89             return OnOffType.from(onOff == 1);
90         }
91
92         public void setOnOff(final OnOffType onOff) {
93             this.onOff = onOff == OnOffType.ON ? 1 : 0;
94         }
95
96         public void setTransition(final int transition) {
97             this.transition = transition;
98         }
99
100         public int getHue() {
101             return groups[0][GROUPS_INDEX_HUE];
102         }
103
104         public int getSaturation() {
105             return groups[0][GROUPS_INDEX_SATURATION];
106         }
107
108         public int getBrightness() {
109             return groups[0][GROUPS_INDEX_BRIGHTNESS];
110         }
111
112         public int getColorTemperature() {
113             return groups[0][GROUPS_INDEX_COLOR_TEMPERATURE];
114         }
115
116         public int[][] getGroups() {
117             return groups;
118         }
119
120         @Override
121         public String toString() {
122             return "onOff:" + onOff + ", mode:" + mode + ", transition:" + transition + ", groups:"
123                     + Arrays.toString(groups);
124         }
125     }
126
127     public static class Context {
128         @Expose
129         private String source = "12345668-1234-1234-1234-123456789012";
130
131         public String getSource() {
132             return source;
133         }
134
135         public void setSource(final String source) {
136             this.source = source;
137         }
138     }
139
140     public static class LightingStrip {
141         @Expose
142         private LightOnOff setLightState;
143
144         @Override
145         public String toString() {
146             return "setLightState:{" + setLightState + "}";
147         }
148     }
149
150     @NonNullByDefault
151     @SerializedName("smartlife.iot.lightStrip")
152     @Expose
153     private final LightingStrip strip = new LightingStrip();
154
155     @Expose(deserialize = false)
156     private Context context;
157
158     public void setLightState(final LightOnOff lightState) {
159         strip.setLightState = lightState;
160     }
161
162     public void setContext(final Context context) {
163         this.context = context;
164     }
165
166     @Override
167     public ErrorResponse getErrorResponse() {
168         return strip.setLightState;
169     }
170
171     @Override
172     public String toString() {
173         return "SetLightState {strip:{" + strip + "}";
174     }
175 }