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 java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.types.StateOption;
22 import com.google.gson.annotations.SerializedName;
25 * This class represents the preset state from the API.
27 * @author Michael Myrcik - Initial contribution
30 public class PresetData {
32 private static final String LABEL_TEMPLATE = "%s fm";
33 private static final String LABEL_EMPTY_TEMPLATE = "FM %s";
36 private @Nullable String preset1;
39 private @Nullable String preset2;
42 private @Nullable String preset3;
45 private @Nullable String preset4;
48 private @Nullable String preset5;
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));
60 private static StateOption createStateOption(String index, @Nullable String preset) {
62 if (preset == null || "".equals(preset)) {
63 label = String.format(LABEL_EMPTY_TEMPLATE, index);
65 label = String.format(LABEL_TEMPLATE, preset);
67 return new StateOption(index, label);