[http] Fix duplicate commands on PlayerItemConverter (#9981)
Fixes #9957 Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
parent
2127ac23c8
commit
8494a0e3ba
|
@ -35,6 +35,7 @@ import org.openhab.core.types.UnDefType;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class PlayerItemConverter extends AbstractTransformingItemConverter {
|
public class PlayerItemConverter extends AbstractTransformingItemConverter {
|
||||||
private final HttpChannelConfig channelConfig;
|
private final HttpChannelConfig channelConfig;
|
||||||
|
private @Nullable String lastCommand; // store last command to prevent duplicate commands
|
||||||
|
|
||||||
public PlayerItemConverter(Consumer<State> updateState, Consumer<Command> postCommand,
|
public PlayerItemConverter(Consumer<State> updateState, Consumer<Command> postCommand,
|
||||||
@Nullable Consumer<String> sendHttpValue, ValueTransformation stateTransformations,
|
@Nullable Consumer<String> sendHttpValue, ValueTransformation stateTransformations,
|
||||||
|
@ -55,6 +56,12 @@ public class PlayerItemConverter extends AbstractTransformingItemConverter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable Command toCommand(String string) {
|
protected @Nullable Command toCommand(String string) {
|
||||||
|
if (string.equals(lastCommand)) {
|
||||||
|
// only send commands once
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
lastCommand = string;
|
||||||
|
|
||||||
if (string.equals(channelConfig.playValue)) {
|
if (string.equals(channelConfig.playValue)) {
|
||||||
return PlayPauseType.PLAY;
|
return PlayPauseType.PLAY;
|
||||||
} else if (string.equals(channelConfig.pauseValue)) {
|
} else if (string.equals(channelConfig.pauseValue)) {
|
||||||
|
|
Loading…
Reference in New Issue