]> git.basschouten.com Git - openhab-addons.git/blob
6ca0781ebe088e676e5883fb8f53e9b46f676b02
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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 Boolean enable = false;
32     private String id = "";
33     private String name = "";
34     private Boolean custom = false;
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     }
46
47     /**
48      * Init DeviceInfo with new Data;
49      * 
50      * @param jso JsonObject new Data
51      */
52     public TapoLightEffect(JsonObject jso) {
53         setData(jso);
54     }
55
56     /**
57      * Set Data (new JsonObject)
58      * 
59      * @param jso JsonObject new Data
60      */
61     public TapoLightEffect setData(JsonObject jso) {
62         /* create empty jsonObject to set efault values if has no lighning effect */
63         if (jso.has(JSON_KEY_LIGHTNING_EFFECT)) {
64             this.jsonObject = jso.getAsJsonObject(JSON_KEY_LIGHTNING_EFFECT);
65             this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ENABLE);
66             this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_ID, JSON_KEY_LIGHTNING_EFFECT_OFF);
67             this.name = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_EFFECT_NAME);
68             this.custom = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_EFFECT_CUSTOM);
69             this.brightness = jsonObjectToInt(jsonObject, JSON_KEY_LIGHTNING_EFFECT_BRIGHNTESS);
70         } else if (jso.has(JSON_KEY_LIGHTNING_DYNAMIC_ENABLE)) {
71             this.jsonObject = jso;
72             this.enable = jsonObjectToBool(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ENABLE);
73             this.id = jsonObjectToString(jsonObject, JSON_KEY_LIGHTNING_DYNAMIC_ID, JSON_KEY_LIGHTNING_EFFECT_OFF);
74         } else {
75             setDefaults();
76         }
77         return this;
78     }
79
80     /**
81      * Set default values
82      */
83     private void setDefaults() {
84         this.jsonObject = new JsonObject();
85         this.enable = false;
86         this.id = JSON_KEY_LIGHTNING_EFFECT_OFF;
87         this.name = "";
88         this.custom = false;
89         this.brightness = 100;
90     }
91
92     /***********************************
93      *
94      * SET VALUES
95      *
96      ************************************/
97
98     public void setEnable(Boolean enable) {
99         this.enable = enable;
100     }
101
102     public void setName(String value) {
103         this.name = value;
104     }
105
106     public void setCustom(Boolean enable) {
107         this.custom = enable;
108     }
109
110     public void setBrightness(Integer value) {
111         this.brightness = value;
112     }
113
114     /***********************************
115      *
116      * GET VALUES
117      *
118      ************************************/
119
120     public Boolean getEnable() {
121         return enable;
122     }
123
124     public String getId() {
125         return id;
126     }
127
128     public String getName() {
129         return name;
130     }
131
132     public Boolean getCustom() {
133         return custom;
134     }
135
136     public Integer getBrightness() {
137         return brightness;
138     }
139
140     public Integer[] getColorTempRange() {
141         return colorTempRange;
142     }
143
144     public Color[] getDisplayColors() {
145         return displayColors;
146     }
147
148     @Override
149     public String toString() {
150         return jsonObject.toString();
151     }
152 }