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.StringType;
21 import org.openhab.core.types.State;
22 import org.openhab.core.types.UnDefType;
24 import com.google.gson.annotations.SerializedName;
27 * This class represents the sunset program state from the API.
29 * @author Michael Myrcik - Initial contribution
32 public class SunsetData {
34 @SerializedName("onoff")
35 private @Nullable Boolean state;
38 * Brightness range from 0 to 25.
40 @SerializedName("curve")
41 private @Nullable Integer lightIntensity;
43 @SerializedName("durat")
44 private @Nullable Integer durationInMin;
46 @SerializedName("ctype")
47 private @Nullable Integer colorSchema;
49 @SerializedName("snddv")
50 private @Nullable String soundSource;
52 @SerializedName("sndch")
53 private @Nullable String ambientNoise;
56 * Volume range from 0 to 25.
58 @SerializedName("sndlv")
59 private @Nullable Integer soundVolume;
61 public State getSwitchState() {
62 final Boolean state = this.state;
64 return UnDefType.NULL;
66 return OnOffType.from(state);
69 public void setState(boolean state) {
73 public State getLightIntensity() {
74 final Integer lightIntensity = this.lightIntensity;
75 if (lightIntensity == null) {
76 return UnDefType.NULL;
78 return new PercentType(lightIntensity * 4);
81 public void setLightIntensity(int percent) {
82 this.lightIntensity = percent / 4;
85 public State getDurationInMin() {
86 final Integer durationInMin = this.durationInMin;
87 if (durationInMin == null) {
88 return UnDefType.NULL;
90 return new DecimalType(durationInMin);
93 public void setDurationInMin(int durationInMin) {
94 this.durationInMin = durationInMin;
97 public State getColorSchema() {
98 final Integer colorSchema = this.colorSchema;
99 if (colorSchema == null) {
100 return UnDefType.NULL;
102 return new DecimalType(colorSchema);
105 public void setColorSchema(int colorSchema) {
106 this.colorSchema = colorSchema;
109 public State getAmbientNoise() {
110 final String soundSource = this.soundSource;
111 if (soundSource == null) {
112 return UnDefType.NULL;
114 final String suffix = "off".equals(soundSource) ? "" : "-" + ambientNoise;
115 return new StringType(soundSource + suffix);
118 public void setAmbientNoise(String option) {
119 final String[] values = option.split("-");
120 soundSource = values[0];
121 ambientNoise = values.length == 1 ? "" : values[1];
124 public State getSoundVolume() {
125 final Integer soundVolume = this.soundVolume;
126 if (soundVolume == null) {
127 return UnDefType.NULL;
129 return new PercentType(soundVolume * 4);
132 public void setSoundVolume(int percent) {
133 this.soundVolume = percent / 4;