]> git.basschouten.com Git - openhab-addons.git/blob
3449f1fa3170347538ad59c9222a18c7c7dddbbf
[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 java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.types.StateOption;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * This class represents the preset state from the API.
26  *
27  * @author Michael Myrcik - Initial contribution
28  */
29 @NonNullByDefault
30 public class PresetData {
31
32     private static final String LABEL_TEMPLATE = "%s fm";
33     private static final String LABEL_EMPTY_TEMPLATE = "FM %s";
34
35     @SerializedName("1")
36     private @Nullable String preset1;
37
38     @SerializedName("2")
39     private @Nullable String preset2;
40
41     @SerializedName("3")
42     private @Nullable String preset3;
43
44     @SerializedName("4")
45     private @Nullable String preset4;
46
47     @SerializedName("5")
48     private @Nullable String preset5;
49
50     public List<StateOption> createPresetOptions() {
51         List<StateOption> stateOptions = new ArrayList<>();
52         stateOptions.add(createStateOption("1", preset1));
53         stateOptions.add(createStateOption("2", preset2));
54         stateOptions.add(createStateOption("3", preset3));
55         stateOptions.add(createStateOption("4", preset4));
56         stateOptions.add(createStateOption("5", preset5));
57         return stateOptions;
58     }
59
60     private static StateOption createStateOption(String index, @Nullable String preset) {
61         String label;
62         if (preset == null || "".equals(preset)) {
63             label = String.format(LABEL_EMPTY_TEMPLATE, index);
64         } else {
65             label = String.format(LABEL_TEMPLATE, preset);
66         }
67         return new StateOption(index, label);
68     }
69 }