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.types.StringType;
22 import org.openhab.core.library.unit.Units;
23 import org.openhab.core.types.State;
24 import org.openhab.core.types.UnDefType;
26 import com.google.gson.annotations.SerializedName;
29 * This class represents the sunset program state from the API.
31 * @author Michael Myrcik - Initial contribution
34 public class SunsetData {
36 @SerializedName("onoff")
37 private @Nullable Boolean state;
40 * Brightness range from 0 to 25.
42 @SerializedName("curve")
43 private @Nullable Integer lightIntensity;
45 @SerializedName("durat")
46 private @Nullable Integer durationInMin;
48 @SerializedName("ctype")
49 private @Nullable Integer colorSchema;
51 @SerializedName("snddv")
52 private @Nullable String soundSource;
54 @SerializedName("sndch")
55 private @Nullable String ambientNoise;
58 * Volume range from 0 to 25.
60 @SerializedName("sndlv")
61 private @Nullable Integer soundVolume;
63 public State getSwitchState() {
64 final Boolean state = this.state;
66 return UnDefType.NULL;
68 return OnOffType.from(state);
71 public void setState(boolean state) {
75 public State getLightIntensity() {
76 final Integer lightIntensity = this.lightIntensity;
77 if (lightIntensity == null) {
78 return UnDefType.NULL;
80 return new PercentType(lightIntensity * 4);
83 public void setLightIntensity(int percent) {
84 this.lightIntensity = percent / 4;
87 public State getDurationInMin() {
88 final Integer durationInMin = this.durationInMin;
89 if (durationInMin == null) {
90 return UnDefType.NULL;
92 return new QuantityType<>(durationInMin, Units.MINUTE);
95 public void setDurationInMin(int durationInMin) {
96 this.durationInMin = durationInMin;
99 public State getColorSchema() {
100 final Integer colorSchema = this.colorSchema;
101 if (colorSchema == null) {
102 return UnDefType.NULL;
104 return new DecimalType(colorSchema);
107 public void setColorSchema(int colorSchema) {
108 this.colorSchema = colorSchema;
111 public State getAmbientNoise() {
112 final String soundSource = this.soundSource;
113 if (soundSource == null) {
114 return UnDefType.NULL;
116 final String suffix = "off".equals(soundSource) ? "" : "-" + ambientNoise;
117 return new StringType(soundSource + suffix);
120 public void setAmbientNoise(String option) {
121 final String[] values = option.split("-");
122 soundSource = values[0];
123 ambientNoise = values.length == 1 ? "" : values[1];
126 public State getSoundVolume() {
127 final Integer soundVolume = this.soundVolume;
128 if (soundVolume == null) {
129 return UnDefType.NULL;
131 return new PercentType(soundVolume * 4);
134 public void setSoundVolume(int percent) {
135 this.soundVolume = percent / 4;