2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.somneo.internal.model;
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;
25 import com.google.gson.annotations.SerializedName;
28 * This class represents the relax program state from the API.
30 * @author Michael Myrcik - Initial contribution
33 public class RelaxData {
35 @SerializedName("onoff")
36 private @Nullable Boolean state;
38 @SerializedName("progr")
39 private @Nullable Integer breathingRate;
41 @SerializedName("durat")
42 private @Nullable Integer durationInMin;
44 @SerializedName("rtype")
45 private @Nullable Integer guidanceType;
48 * Brightness range from 0 to 25.
50 @SerializedName("intny")
51 private @Nullable Integer lightIntensity;
54 * Volume range from 0 to 25.
56 @SerializedName("sndlv")
57 private @Nullable Integer soundVolume;
59 public State getSwitchState() {
60 final Boolean state = this.state;
62 return UnDefType.NULL;
64 return OnOffType.from(state);
67 public void setState(boolean state) {
71 public State getBreathingRate() {
72 final Integer breathingRate = this.breathingRate;
73 if (breathingRate == null) {
74 return UnDefType.NULL;
76 return new DecimalType(breathingRate);
79 public void setBreathingRate(int breathingRate) {
80 this.breathingRate = breathingRate;
83 public State getDurationInMin() {
84 final Integer durationInMin = this.durationInMin;
85 if (durationInMin == null) {
86 return UnDefType.NULL;
88 return new QuantityType<>(durationInMin, Units.MINUTE);
91 public void setDurationInMin(int durationInMin) {
92 this.durationInMin = durationInMin;
95 public State getGuidanceType() {
96 final Integer guidanceType = this.guidanceType;
97 if (guidanceType == null) {
98 return UnDefType.NULL;
100 return new DecimalType(guidanceType);
103 public void setGuidanceType(int guidanceType) {
104 this.guidanceType = guidanceType;
107 public State getLightIntensity() {
108 final Integer lightIntensity = this.lightIntensity;
109 if (lightIntensity == null) {
110 return UnDefType.NULL;
112 return new PercentType(lightIntensity * 4);
115 public void setLightIntensity(int percent) {
116 this.lightIntensity = percent / 4;
119 public State getSoundVolume() {
120 final Integer soundVolume = this.soundVolume;
121 if (soundVolume == null) {
122 return UnDefType.NULL;
124 return new PercentType(soundVolume * 4);
127 public void setSoundVolume(int percent) {
128 this.soundVolume = percent / 4;