]> git.basschouten.com Git - openhab-addons.git/blob
0352191ce59ea9511f8faad0c1ece622fb6101da
[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.types.State;
21 import org.openhab.core.types.UnDefType;
22
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  * This class represents the relax program state from the API.
27  *
28  * @author Michael Myrcik - Initial contribution
29  */
30 @NonNullByDefault
31 public class RelaxData {
32
33     @SerializedName("onoff")
34     private @Nullable Boolean state;
35
36     @SerializedName("progr")
37     private @Nullable Integer breathingRate;
38
39     @SerializedName("durat")
40     private @Nullable Integer durationInMin;
41
42     @SerializedName("rtype")
43     private @Nullable Integer guidanceType;
44
45     /**
46      * Brightness range from 0 to 25.
47      */
48     @SerializedName("intny")
49     private @Nullable Integer lightIntensity;
50
51     /**
52      * Volume range from 0 to 25.
53      */
54     @SerializedName("sndlv")
55     private @Nullable Integer soundVolume;
56
57     public State getSwitchState() {
58         final Boolean state = this.state;
59         if (state == null) {
60             return UnDefType.NULL;
61         }
62         return OnOffType.from(state);
63     }
64
65     public void setState(boolean state) {
66         this.state = state;
67     }
68
69     public State getBreathingRate() {
70         final Integer breathingRate = this.breathingRate;
71         if (breathingRate == null) {
72             return UnDefType.NULL;
73         }
74         return new DecimalType(breathingRate);
75     }
76
77     public void setBreathingRate(int breathingRate) {
78         this.breathingRate = breathingRate;
79     }
80
81     public State getDurationInMin() {
82         final Integer durationInMin = this.durationInMin;
83         if (durationInMin == null) {
84             return UnDefType.NULL;
85         }
86         return new DecimalType(durationInMin);
87     }
88
89     public void setDurationInMin(int durationInMin) {
90         this.durationInMin = durationInMin;
91     }
92
93     public State getGuidanceType() {
94         final Integer guidanceType = this.guidanceType;
95         if (guidanceType == null) {
96             return UnDefType.NULL;
97         }
98         return new DecimalType(guidanceType);
99     }
100
101     public void setGuidanceType(int guidanceType) {
102         this.guidanceType = guidanceType;
103     }
104
105     public State getLightIntensity() {
106         final Integer lightIntensity = this.lightIntensity;
107         if (lightIntensity == null) {
108             return UnDefType.NULL;
109         }
110         return new PercentType(lightIntensity * 4);
111     }
112
113     public void setLightIntensity(int percent) {
114         this.lightIntensity = percent / 4;
115     }
116
117     public State getSoundVolume() {
118         final Integer soundVolume = this.soundVolume;
119         if (soundVolume == null) {
120             return UnDefType.NULL;
121         }
122         return new PercentType(soundVolume * 4);
123     }
124
125     public void setSoundVolume(int percent) {
126         this.soundVolume = percent / 4;
127     }
128 }