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