]> git.basschouten.com Git - openhab-addons.git/blob
099b78aaf76b82290b9796d99c1108ea375ef6d8
[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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.OnOffType;
17
18 import com.google.gson.annotations.SerializedName;
19
20 /**
21  * Data class to setting different kind of states on Smart Home light bulbs.
22  * Only setter methods as the object is only used to send values.
23  *
24  * @author Hilbrand Bouwkamp - Initial contribution
25  */
26 public class TransitionLightState {
27
28     /**
29      * Color sets hue, saturation and brightness.
30      * color temperature present to send with default 0 value to bulb.
31      */
32     public static class LightStateColor extends LightStateBrightness {
33         private int colorTemp;
34         private int hue;
35         private int saturation;
36
37         public void setHue(int hue) {
38             this.hue = hue;
39         }
40
41         public void setSaturation(int saturation) {
42             this.saturation = saturation;
43         }
44
45         @Override
46         public String toString() {
47             return "colorTemp" + colorTemp + ", hue:" + hue + ", saturation:" + saturation + ", " + super.toString();
48         }
49     }
50
51     /**
52      * Color Temperature doesn't set brightness therefore separate class.
53      * hue and saturation present to send with default 0 value to bulb.
54      */
55     public static class LightStateColorTemperature extends LightOnOff {
56         private int colorTemp;
57         private int hue;
58         private int saturation;
59
60         public void setColorTemperature(int colorTemp) {
61             this.colorTemp = colorTemp;
62         }
63
64         @Override
65         public String toString() {
66             return "colorTemp" + colorTemp + ", hue:" + hue + ", saturation:" + saturation + ", " + super.toString();
67         }
68     }
69
70     public static class LightStateBrightness extends LightOnOff {
71         private int brightness;
72
73         public void setBrightness(int brightness) {
74             this.brightness = brightness;
75         }
76
77         @Override
78         public String toString() {
79             return "brightness:" + brightness + ", " + super.toString();
80         }
81     }
82
83     public static class LightOnOff {
84         private int onOff;
85         private int ignoreDefault = 1;
86         private String mode = "normal";
87         private int transitionPeriod;
88
89         public void setOnOff(OnOffType onOff) {
90             this.onOff = onOff == OnOffType.ON ? 1 : 0;
91         }
92
93         public void setTransitionPeriod(int transitionPeriod) {
94             this.transitionPeriod = transitionPeriod;
95         }
96
97         @Override
98         public String toString() {
99             return "onOff:" + onOff + ", ignoreDefault:" + ignoreDefault + ", mode:" + mode + ", transitionPeriod:"
100                     + transitionPeriod;
101         }
102     }
103
104     public static class LightingService {
105         private LightOnOff transitionLightState;
106
107         @Override
108         public String toString() {
109             return "transitionLightState:{" + transitionLightState + "}";
110         }
111     }
112
113     @NonNullByDefault
114     @SerializedName("smartlife.iot.smartbulb.lightingservice")
115     private LightingService service = new LightingService();
116
117     public void setLightState(LightOnOff lightState) {
118         service.transitionLightState = lightState;
119     }
120
121     @Override
122     public String toString() {
123         return "TransitionLightState {service:{" + service + "}";
124     }
125 }