2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.tapocontrol.internal.structures;
15 import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
16 import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
18 import java.awt.Color;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import com.google.gson.JsonObject;
25 * Tapo-LightningEffect Structure Class
27 * @author Christian Wild - Initial contribution
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 };
39 private JsonObject jsonObject = new JsonObject();
44 public TapoLightEffect() {
48 * Init DeviceInfo with new Data;
50 * @param jso JsonObject new Data
52 public TapoLightEffect(JsonObject jso) {
57 * Set Data (new JsonObject)
59 * @param jso JsonObject new Data
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);
83 private void setDefaults() {
84 this.jsonObject = new JsonObject();
86 this.id = JSON_KEY_LIGHTNING_EFFECT_OFF;
89 this.brightness = 100;
92 /***********************************
96 ************************************/
98 public void setEnable(Boolean enable) {
102 public void setName(String value) {
106 public void setCustom(Boolean enable) {
107 this.custom = enable;
110 public void setBrightness(Integer value) {
111 this.brightness = value;
114 /***********************************
118 ************************************/
120 public Boolean getEnable() {
124 public String getId() {
128 public String getName() {
132 public Boolean getCustom() {
136 public Integer getBrightness() {
140 public Integer[] getColorTempRange() {
141 return colorTempRange;
144 public Color[] getDisplayColors() {
145 return displayColors;
149 public String toString() {
150 return jsonObject.toString();