2 * Copyright (c) 2010-2021 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.http.internal.config;
15 import java.math.BigDecimal;
16 import java.util.HashMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.http.internal.converter.ColorItemConverter;
22 import org.openhab.core.library.types.IncreaseDecreaseType;
23 import org.openhab.core.library.types.NextPreviousType;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.library.types.OpenClosedType;
26 import org.openhab.core.library.types.PlayPauseType;
27 import org.openhab.core.library.types.RewindFastforwardType;
28 import org.openhab.core.library.types.StopMoveType;
29 import org.openhab.core.library.types.UpDownType;
30 import org.openhab.core.types.Command;
31 import org.openhab.core.types.State;
34 * The {@link HttpChannelConfig} class contains fields mapping channel configuration parameters.
36 * @author Jan N. Klug - Initial contribution
39 public class HttpChannelConfig {
40 private final Map<String, State> stringStateMap = new HashMap<>();
41 private final Map<Command, @Nullable String> commandStringMap = new HashMap<>();
42 private boolean initialized = false;
44 public @Nullable String stateExtension;
45 public @Nullable String commandExtension;
46 public @Nullable String stateTransformation;
47 public @Nullable String commandTransformation;
49 public HttpChannelMode mode = HttpChannelMode.READWRITE;
51 // switch, dimmer, color
52 public @Nullable String onValue;
53 public @Nullable String offValue;
56 public BigDecimal step = BigDecimal.ONE;
57 public @Nullable String increaseValue;
58 public @Nullable String decreaseValue;
61 public ColorItemConverter.ColorMode colorMode = ColorItemConverter.ColorMode.RGB;
64 public @Nullable String openValue;
65 public @Nullable String closedValue;
68 public @Nullable String upValue;
69 public @Nullable String downValue;
70 public @Nullable String stopValue;
71 public @Nullable String moveValue;
74 public @Nullable String playValue;
75 public @Nullable String pauseValue;
76 public @Nullable String nextValue;
77 public @Nullable String previousValue;
78 public @Nullable String rewindValue;
79 public @Nullable String fastforwardValue;
82 * maps a command to a user-defined string
84 * @param command the command to map
85 * @return a string or null if no mapping found
87 public @Nullable String commandToFixedValue(Command command) {
92 return commandStringMap.get(command);
96 * maps a user-defined string to a state
98 * @param string the string to map
99 * @return the state or null if no mapping found
101 public @Nullable State fixedValueToState(String string) {
106 return stringStateMap.get(string);
109 private void createMaps() {
110 addToMaps(this.onValue, OnOffType.ON);
111 addToMaps(this.offValue, OnOffType.OFF);
112 addToMaps(this.openValue, OpenClosedType.OPEN);
113 addToMaps(this.closedValue, OpenClosedType.CLOSED);
114 addToMaps(this.upValue, UpDownType.UP);
115 addToMaps(this.downValue, UpDownType.DOWN);
117 commandStringMap.put(IncreaseDecreaseType.INCREASE, increaseValue);
118 commandStringMap.put(IncreaseDecreaseType.DECREASE, decreaseValue);
119 commandStringMap.put(StopMoveType.STOP, stopValue);
120 commandStringMap.put(StopMoveType.MOVE, moveValue);
121 commandStringMap.put(PlayPauseType.PLAY, playValue);
122 commandStringMap.put(PlayPauseType.PAUSE, pauseValue);
123 commandStringMap.put(NextPreviousType.NEXT, nextValue);
124 commandStringMap.put(NextPreviousType.PREVIOUS, previousValue);
125 commandStringMap.put(RewindFastforwardType.REWIND, rewindValue);
126 commandStringMap.put(RewindFastforwardType.FASTFORWARD, fastforwardValue);
131 private void addToMaps(@Nullable String value, State state) {
133 commandStringMap.put((Command) state, value);
134 stringStateMap.put(value, state);