]> git.basschouten.com Git - openhab-addons.git/blob
7c4342f8ba17f1e1ece5700eb12ecbe03e50a375
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.somneo.internal.model;
14
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;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * This class represents the radio state from the API.
25  *
26  * @author Michael Myrcik - Initial contribution
27  */
28 @NonNullByDefault
29 public class RadioData {
30
31     private static final String LABEL_TEMPLATE = "%s fm";
32
33     private static final String CMD_SEEK_UP = "seekup";
34
35     private static final String CMD_SEEK_DOWN = "seekdown";
36
37     @SerializedName("fmfrq")
38     private @Nullable String frequency;
39
40     @SerializedName("fmcmd")
41     private @Nullable String command;
42
43     public State getFrequency() {
44         final String frequency = this.frequency;
45         if (frequency == null) {
46             return UnDefType.NULL;
47         }
48         return new StringType(String.format(LABEL_TEMPLATE, frequency));
49     }
50
51     public void setCmdSeekUp() {
52         this.command = CMD_SEEK_UP;
53     }
54
55     public void setCmdSeekDown() {
56         this.command = CMD_SEEK_DOWN;
57     }
58
59     public boolean isSeeking() {
60         return CMD_SEEK_UP.equals(command) || CMD_SEEK_DOWN.equals(command);
61     }
62 }