]> git.basschouten.com Git - openhab-addons.git/blob
dd9c829cace6a0e1a8803e7574efa5f9f5857516
[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.tapocontrol.internal.structures;
14
15 import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
16 import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
17
18 import java.awt.Color;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21
22 import com.google.gson.JsonObject;
23
24 /**
25  * Tapo-LightningEffect Structure Class
26  *
27  * @author Christian Wild - Initial contribution
28  */
29 @NonNullByDefault
30 public class TapoLightEffect {
31     private Integer enable = 0;
32     private String id = "";
33     private String name = "";
34     private Integer custom = 0;
35     private Integer brightness = 0;
36     private Integer[] colorTempRange = { 9000, 9000 }; // :[9000,9000]
37     private Color displayColors[] = { Color.WHITE };
38
39     private JsonObject jsonObject = new JsonObject();
40
41     /**
42      * INIT
43      */
44     public TapoLightEffect() {
45         setData();
46     }
47
48     /**
49      * Init DeviceInfo with new Data;
50      * 
51      * @param jso JsonObject new Data
52      */
53     public TapoLightEffect(JsonObject jso) {
54         setData(jso);
55     }
56
57     /**
58      * Set Data (new JsonObject)
59      * 
60      * @param jso JsonObject new Data
61      */
62     public TapoLightEffect setData(JsonObject jso) {
63         /* create empty jsonObject to set efault values if has no lighning effect */
64         if (jso.has(DEVICE_PROPERTY_EFFECT)) {
65             this.jsonObject = jso;
66         } else {
67             jsonObject = new JsonObject();
68         }
69         setData();
70         return this;
71     }
72
73     private void setData() {
74         this.enable = jsonObjectToInt(jsonObject, PROPERTY_LIGHTNING_EFFECT_ENABLE);
75         this.id = jsonObjectToString(jsonObject, PROPERTY_LIGHTNING_EFFECT_ID);
76         this.name = jsonObjectToString(jsonObject, PROPERTY_LIGHTNING_EFFECT_NAME);
77         this.custom = jsonObjectToInt(jsonObject, PROPERTY_LIGHTNING_EFFECT_CUSTOM); // jsonObjectToBool
78         this.brightness = jsonObjectToInt(jsonObject, PROPERTY_LIGHTNING_EFFECT_BRIGHNTESS);
79     }
80
81     /***********************************
82      *
83      * SET VALUES
84      *
85      ************************************/
86
87     public void setEnable(Boolean enable) {
88         this.enable = enable ? 1 : 0;
89     }
90
91     public void setName(String value) {
92         this.name = value;
93     }
94
95     public void setCustom(Boolean enable) {
96         this.custom = enable ? 1 : 0;
97     }
98
99     public void setBrightness(Integer value) {
100         this.brightness = value;
101     }
102
103     /***********************************
104      *
105      * GET VALUES
106      *
107      ************************************/
108
109     public Integer getEnable() {
110         return this.enable;
111     }
112
113     public String getId() {
114         return this.id;
115     }
116
117     public String getName() {
118         return this.name;
119     }
120
121     public Integer getCustom() {
122         return this.custom;
123     }
124
125     public Integer getBrightness() {
126         return this.brightness;
127     }
128
129     public Integer[] getColorTempRange() {
130         return this.colorTempRange;
131     }
132
133     public Color[] getDisplayColors() {
134         return this.displayColors;
135     }
136
137     @Override
138     public String toString() {
139         return jsonObject.toString();
140     }
141 }