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