2 * Copyright (c) 2010-2022 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.StringType;
18 import org.openhab.core.types.State;
19 import org.openhab.core.types.UnDefType;
21 import com.google.gson.annotations.SerializedName;
24 * This class represents the radio state from the API.
26 * @author Michael Myrcik - Initial contribution
29 public class RadioData {
31 private static final String LABEL_TEMPLATE = "%s fm";
33 private static final String CMD_SEEK_UP = "seekup";
35 private static final String CMD_SEEK_DOWN = "seekdown";
37 @SerializedName("fmfrq")
38 private @Nullable String frequency;
40 @SerializedName("fmcmd")
41 private @Nullable String command;
43 public State getFrequency() {
44 final String frequency = this.frequency;
45 if (frequency == null) {
46 return UnDefType.NULL;
48 return new StringType(String.format(LABEL_TEMPLATE, frequency));
51 public void setCmdSeekUp() {
52 this.command = CMD_SEEK_UP;
55 public void setCmdSeekDown() {
56 this.command = CMD_SEEK_DOWN;
59 public boolean isSeeking() {
60 return CMD_SEEK_UP.equals(command) || CMD_SEEK_DOWN.equals(command);