]> git.basschouten.com Git - openhab-addons.git/blob
37e119ca8cdde0021413afe9686cf2ef199519e3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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         return (on != null && on.getValue()) ? OnOffType.ON : OnOffType.OFF;
45     }
46
47     public void setOn(On on) {
48         this.on = on;
49     }
50
51     public @Nullable Brightness getBrightness() {
52         return brightness;
53     }
54
55     public void setBrightness(Brightness brightness) {
56         this.brightness = brightness;
57     }
58
59     public @Nullable Hue getHue() {
60         return hue;
61     }
62
63     public void setHue(Hue hue) {
64         this.hue = hue;
65     }
66
67     public @Nullable Sat getSaturation() {
68         return saturation;
69     }
70
71     public void setSaturation(Sat sat) {
72         this.saturation = sat;
73     }
74
75     public @Nullable Ct getColorTemperature() {
76         return colorTemperature;
77     }
78
79     public void setColorTemperature(Ct ct) {
80         this.colorTemperature = ct;
81     }
82
83     public @Nullable String getColorMode() {
84         return colorMode;
85     }
86
87     public void setColorMode(String colorMode) {
88         this.colorMode = colorMode;
89     }
90
91     public void setState(IntegerState value) {
92         if (value instanceof Brightness) {
93             this.setBrightness((Brightness) value);
94         } else if (value instanceof Hue) {
95             this.setHue((Hue) value);
96         } else if (value instanceof Sat) {
97             this.setSaturation((Sat) value);
98         } else if (value instanceof Ct) {
99             this.setColorTemperature((Ct) value);
100         }
101     }
102
103     public void setState(BooleanState value) {
104         if (value instanceof On) {
105             this.setOn((On) value);
106         }
107     }
108 }