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.OnOffType;
18 import org.openhab.core.library.types.PercentType;
19 import org.openhab.core.library.types.PlayPauseType;
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 audio state from the API.
29 * @author Michael Myrcik - Initial contribution
32 public class AudioData {
34 private static final String SOURCE_RADIO = "fmr";
36 private static final String SOURCE_AUX = "aux";
38 private static final String SOURCE_OFF = "off";
40 @SerializedName("onoff")
41 private @Nullable Boolean power;
44 * Must be set to false when the audio is turned on, otherwise a light that is
45 * turned on will be turned off.
47 @SuppressWarnings("unused")
48 @SerializedName("tempy")
49 private @Nullable Boolean previewLight;
52 * Volume range from 0 to 25.
54 @SerializedName("sdvol")
55 private @Nullable Integer volume;
58 * Current active audio source. Can be radio, aux or off.
60 @SerializedName("snddv")
61 private @Nullable String source;
64 * Current active radio preset.
66 @SerializedName("sndch")
67 private @Nullable String preset;
69 public void disableAudio() {
74 public void enableRadio() {
76 source = SOURCE_RADIO;
80 public State getRadioState() {
81 final Boolean power = this.power;
83 return UnDefType.NULL;
85 return power && SOURCE_RADIO.equals(source) ? PlayPauseType.PLAY : PlayPauseType.PAUSE;
88 public void enableAux() {
94 public State getAuxState() {
95 final Boolean power = this.power;
97 return UnDefType.NULL;
99 return OnOffType.from(power && SOURCE_AUX.equals(source));
102 public void setVolume(int percent) {
103 this.volume = percent / 4;
106 public State getVolumeState() {
107 final Integer volume = this.volume;
108 if (volume == null) {
109 return UnDefType.NULL;
111 return new PercentType(volume * 4);
114 public void setRadioPreset(String preset) {
115 this.preset = preset;
118 public State getPresetState() {
119 final String preset = this.preset;
120 if (preset == null) {
121 return UnDefType.NULL;
123 return new StringType(preset);