]> git.basschouten.com Git - openhab-addons.git/blob
5cf5dad22d4031aabf788cb14d71fd032bbe01e7
[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.nanoleaf.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.OnOffType;
18
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * Represents overall state settings of the light panels
23  *
24  * @author Martin Raepple - Initial contribution
25  */
26 @NonNullByDefault
27 public class State {
28
29     private @Nullable On on;
30     private @Nullable Brightness brightness;
31     private @Nullable Hue hue;
32     @SerializedName("sat")
33     private @Nullable Sat saturation;
34     @SerializedName("ct")
35     private @Nullable Ct colorTemperature;
36
37     private @Nullable String colorMode;
38
39     public @Nullable On getOn() {
40         return on;
41     }
42
43     public OnOffType getOnOff() {
44         On localOn = on;
45         return (localOn != null && localOn.getValue()) ? OnOffType.ON : OnOffType.OFF;
46     }
47
48     public void setOn(On on) {
49         this.on = on;
50     }
51
52     public @Nullable Brightness getBrightness() {
53         return brightness;
54     }
55
56     public void setBrightness(Brightness brightness) {
57         this.brightness = brightness;
58     }
59
60     public @Nullable Hue getHue() {
61         return hue;
62     }
63
64     public void setHue(Hue hue) {
65         this.hue = hue;
66     }
67
68     public @Nullable Sat getSaturation() {
69         return saturation;
70     }
71
72     public void setSaturation(Sat sat) {
73         this.saturation = sat;
74     }
75
76     public @Nullable Ct getColorTemperature() {
77         return colorTemperature;
78     }
79
80     public void setColorTemperature(Ct ct) {
81         this.colorTemperature = ct;
82     }
83
84     public @Nullable String getColorMode() {
85         return colorMode;
86     }
87
88     public void setColorMode(String colorMode) {
89         this.colorMode = colorMode;
90     }
91
92     public void setState(IntegerState value) {
93         if (value instanceof Brightness) {
94             this.setBrightness((Brightness) value);
95         } else if (value instanceof Hue) {
96             this.setHue((Hue) value);
97         } else if (value instanceof Sat) {
98             this.setSaturation((Sat) value);
99         } else if (value instanceof Ct) {
100             this.setColorTemperature((Ct) value);
101         }
102     }
103
104     public void setState(BooleanState value) {
105         if (value instanceof On) {
106             this.setOn((On) value);
107         }
108     }
109 }