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.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.library.types.NextPreviousType;
22 import org.openhab.core.library.types.PlayPauseType;
23 import org.openhab.core.library.types.RewindFastforwardType;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
29 * The {@link PlayerItemConverter} implements {@link org.openhab.core.library.items.RollershutterItem}
32 * @author Jan N. Klug - Initial contribution
36 public class PlayerItemConverter extends AbstractTransformingItemConverter {
37 private final HttpChannelConfig channelConfig;
39 public PlayerItemConverter(Consumer<State> updateState, Consumer<Command> postCommand,
40 @Nullable Consumer<String> sendHttpValue, ValueTransformation stateTransformations,
41 ValueTransformation commandTransformations, HttpChannelConfig channelConfig) {
42 super(updateState, postCommand, sendHttpValue, stateTransformations, commandTransformations, channelConfig);
43 this.channelConfig = channelConfig;
47 public String toString(Command command) {
48 String string = channelConfig.commandToFixedValue(command);
53 throw new IllegalArgumentException("Command type '" + command.toString() + "' not supported");
57 protected @Nullable Command toCommand(String string) {
58 if (string.equals(channelConfig.playValue)) {
59 return PlayPauseType.PLAY;
60 } else if (string.equals(channelConfig.pauseValue)) {
61 return PlayPauseType.PAUSE;
62 } else if (string.equals(channelConfig.nextValue)) {
63 return NextPreviousType.NEXT;
64 } else if (string.equals(channelConfig.previousValue)) {
65 return NextPreviousType.PREVIOUS;
66 } else if (string.equals(channelConfig.rewindValue)) {
67 return RewindFastforwardType.REWIND;
68 } else if (string.equals(channelConfig.fastforwardValue)) {
69 return RewindFastforwardType.FASTFORWARD;
76 public State toState(String string) {
77 return UnDefType.UNDEF;