2 * Copyright (c) 2010-2024 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.converter;
15 import java.util.function.Consumer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.http.internal.config.HttpChannelConfig;
20 import org.openhab.binding.http.internal.transform.ValueTransformation;
21 import org.openhab.core.types.Command;
22 import org.openhab.core.types.State;
23 import org.openhab.core.types.UnDefType;
26 * The {@link FixedValueMappingItemConverter} implements mapping conversions for different item-types
28 * @author Jan N. Klug - Initial contribution
32 public class FixedValueMappingItemConverter extends AbstractTransformingItemConverter {
34 public FixedValueMappingItemConverter(Consumer<State> updateState, Consumer<Command> postCommand,
35 @Nullable Consumer<String> sendHttpValue, ValueTransformation stateTransformations,
36 ValueTransformation commandTransformations, HttpChannelConfig channelConfig) {
37 super(updateState, postCommand, sendHttpValue, stateTransformations, commandTransformations, channelConfig);
41 protected @Nullable Command toCommand(String value) {
46 public String toString(Command command) {
47 String value = channelConfig.commandToFixedValue(command);
52 throw new IllegalArgumentException(
53 "Command type '" + command.toString() + "' not supported or mapping not defined.");
57 public State toState(String string) {
58 State state = channelConfig.fixedValueToState(string);
60 return state != null ? state : UnDefType.UNDEF;