]> git.basschouten.com Git - openhab-addons.git/blob
2879c9d6f72e0a60353dc4fe2ccb8c1024b1795b
[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.hue.internal.api.dto.clip1;
14
15 import java.util.Arrays;
16
17 /**
18  * Current state of light.
19  *
20  * @author Q42 - Initial contribution
21  * @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding
22  * @author Laurent Garnier - add few methods to update the object
23  */
24 public class State {
25     private boolean on;
26     public int bri;
27     public int hue;
28     public int sat;
29     private float[] xy;
30     public int ct;
31     private String alert;
32     private String effect;
33     public String colormode;
34     private boolean reachable;
35
36     public State() {
37     }
38
39     /**
40      * Color modes of a light.
41      */
42     public enum ColorMode {
43         /**
44          * CIE color space coordinates
45          */
46         XY,
47
48         /**
49          * Hue and saturation
50          */
51         HS,
52
53         /**
54          * Color temperature in mired
55          */
56         CT
57     }
58
59     /**
60      * Alert modes of a light.
61      */
62     public enum AlertMode {
63         /**
64          * Light is not performing alert effect
65          */
66         NONE,
67
68         /**
69          * Light is performing one breathe cycle
70          */
71         SELECT,
72
73         /**
74          * Light is performing breathe cycles for 30 seconds (unless cancelled)
75          */
76         LSELECT
77     }
78
79     /**
80      * Effects possible for a light.
81      */
82     public enum Effect {
83         /**
84          * No effect
85          */
86         NONE,
87
88         /**
89          * Cycle through all hues with current saturation and brightness
90          */
91         COLORLOOP
92     }
93
94     /**
95      * Returns the on state.
96      *
97      * @return true if the light is on, false if it isn't
98      */
99     public boolean isOn() {
100         return on;
101     }
102
103     public void setOn(boolean on) {
104         this.on = on;
105     }
106
107     /**
108      * Returns the brightness.
109      *
110      * @return brightness
111      */
112     public int getBrightness() {
113         return bri;
114     }
115
116     public void setBri(int bri) {
117         this.bri = bri;
118     }
119
120     /**
121      * Returns the hue.
122      *
123      * @return hue
124      */
125     public int getHue() {
126         return hue;
127     }
128
129     public void setHue(int hue) {
130         this.hue = hue;
131     }
132
133     /**
134      * Returns the saturation.
135      *
136      * @return saturation
137      */
138     public int getSaturation() {
139         return sat;
140     }
141
142     public void setSaturation(int sat) {
143         this.sat = sat;
144     }
145
146     /**
147      * Returns the coordinates in CIE color space.
148      *
149      * @return cie color spaces coordinates
150      */
151     public float[] getXY() {
152         return xy;
153     }
154
155     public void setXY(float[] xy) {
156         this.xy = xy;
157     }
158
159     /**
160      * Returns the color temperature.
161      *
162      * @return color temperature
163      */
164     public int getColorTemperature() {
165         return ct;
166     }
167
168     public void setColorTemperature(int ct) {
169         this.ct = ct;
170     }
171
172     /**
173      * Returns the last alert mode set.
174      * Future firmware updates may change this to actually report the current alert mode.
175      *
176      * @return last alert mode
177      */
178     public AlertMode getAlertMode() {
179         if (alert == null) {
180             return null;
181         }
182         return AlertMode.valueOf(alert.toUpperCase());
183     }
184
185     /**
186      * Returns the current color mode.
187      *
188      * @return current color mode
189      */
190     public ColorMode getColorMode() {
191         if (colormode == null) {
192             return null;
193         }
194         return ColorMode.valueOf(colormode.toUpperCase());
195     }
196
197     public void setColormode(ColorMode colormode) {
198         this.colormode = colormode.name();
199     }
200
201     /**
202      * Returns the current active effect.
203      *
204      * @return current active effect
205      */
206     public Effect getEffect() {
207         if (effect == null) {
208             return null;
209         }
210         return Effect.valueOf(effect.toUpperCase());
211     }
212
213     /**
214      * Returns reachability.
215      *
216      * @return true if reachable, false if it isn't
217      */
218     public boolean isReachable() {
219         return reachable;
220     }
221
222     @Override
223     public int hashCode() {
224         final int prime = 31;
225         int result = 1;
226         result = prime * result + ((alert == null) ? 0 : alert.hashCode());
227         result = prime * result + bri;
228         result = prime * result + ((colormode == null) ? 0 : colormode.hashCode());
229         result = prime * result + ct;
230         result = prime * result + ((effect == null) ? 0 : effect.hashCode());
231         result = prime * result + hue;
232         result = prime * result + (on ? 1231 : 1237);
233         result = prime * result + (reachable ? 1231 : 1237);
234         result = prime * result + sat;
235         result = prime * result + Arrays.hashCode(xy);
236         return result;
237     }
238
239     @Override
240     public boolean equals(Object obj) {
241         if (this == obj) {
242             return true;
243         }
244         if (obj == null) {
245             return false;
246         }
247         if (getClass() != obj.getClass()) {
248             return false;
249         }
250         State other = (State) obj;
251         if (alert == null) {
252             if (other.alert != null) {
253                 return false;
254             }
255         } else if (!alert.equals(other.alert)) {
256             return false;
257         }
258         if (bri != other.bri) {
259             return false;
260         }
261         if (colormode == null) {
262             if (other.colormode != null) {
263                 return false;
264             }
265         } else if (!colormode.equals(other.colormode)) {
266             return false;
267         }
268         if (ct != other.ct) {
269             return false;
270         }
271         if (effect == null) {
272             if (other.effect != null) {
273                 return false;
274             }
275         } else if (!effect.equals(other.effect)) {
276             return false;
277         }
278         if (hue != other.hue) {
279             return false;
280         }
281         if (on != other.on) {
282             return false;
283         }
284         if (reachable != other.reachable) {
285             return false;
286         }
287         if (sat != other.sat) {
288             return false;
289         }
290         return Arrays.equals(xy, other.xy);
291     }
292 }