]> git.basschouten.com Git - openhab-addons.git/blob
7b851d721f1b17c4e8d757e5efc43b24693fe9d3
[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.somneo.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.library.types.PercentType;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.types.State;
22 import org.openhab.core.types.UnDefType;
23
24 import com.google.gson.annotations.SerializedName;
25
26 /**
27  * This class represents the sunset program state from the API.
28  *
29  * @author Michael Myrcik - Initial contribution
30  */
31 @NonNullByDefault
32 public class SunsetData {
33
34     @SerializedName("onoff")
35     private @Nullable Boolean state;
36
37     /**
38      * Brightness range from 0 to 25.
39      */
40     @SerializedName("curve")
41     private @Nullable Integer lightIntensity;
42
43     @SerializedName("durat")
44     private @Nullable Integer durationInMin;
45
46     @SerializedName("ctype")
47     private @Nullable Integer colorSchema;
48
49     @SerializedName("snddv")
50     private @Nullable String soundSource;
51
52     @SerializedName("sndch")
53     private @Nullable String ambientNoise;
54
55     /**
56      * Volume range from 0 to 25.
57      */
58     @SerializedName("sndlv")
59     private @Nullable Integer soundVolume;
60
61     public State getSwitchState() {
62         final Boolean state = this.state;
63         if (state == null) {
64             return UnDefType.NULL;
65         }
66         return OnOffType.from(state);
67     }
68
69     public void setState(boolean state) {
70         this.state = state;
71     }
72
73     public State getLightIntensity() {
74         final Integer lightIntensity = this.lightIntensity;
75         if (lightIntensity == null) {
76             return UnDefType.NULL;
77         }
78         return new PercentType(lightIntensity * 4);
79     }
80
81     public void setLightIntensity(int percent) {
82         this.lightIntensity = percent / 4;
83     }
84
85     public State getDurationInMin() {
86         final Integer durationInMin = this.durationInMin;
87         if (durationInMin == null) {
88             return UnDefType.NULL;
89         }
90         return new DecimalType(durationInMin);
91     }
92
93     public void setDurationInMin(int durationInMin) {
94         this.durationInMin = durationInMin;
95     }
96
97     public State getColorSchema() {
98         final Integer colorSchema = this.colorSchema;
99         if (colorSchema == null) {
100             return UnDefType.NULL;
101         }
102         return new DecimalType(colorSchema);
103     }
104
105     public void setColorSchema(int colorSchema) {
106         this.colorSchema = colorSchema;
107     }
108
109     public State getAmbientNoise() {
110         final String soundSource = this.soundSource;
111         if (soundSource == null) {
112             return UnDefType.NULL;
113         }
114         final String suffix = "off".equals(soundSource) ? "" : "-" + ambientNoise;
115         return new StringType(soundSource + suffix);
116     }
117
118     public void setAmbientNoise(String option) {
119         final String[] values = option.split("-");
120         soundSource = values[0];
121         ambientNoise = values.length == 1 ? "" : values[1];
122     }
123
124     public State getSoundVolume() {
125         final Integer soundVolume = this.soundVolume;
126         if (soundVolume == null) {
127             return UnDefType.NULL;
128         }
129         return new PercentType(soundVolume * 4);
130     }
131
132     public void setSoundVolume(int percent) {
133         this.soundVolume = percent / 4;
134     }
135 }