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.serial.internal.channel;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.serial.internal.transform.ValueTransformationProvider;
19 import org.openhab.core.library.types.StopMoveType;
20 import org.openhab.core.library.types.UpDownType;
21 import org.openhab.core.types.Command;
24 * The {@link RollershutterChannel} channel provides mappings for the UP, DOWN and STOP commands
26 * @author Mike Major - Initial contribution
29 public class RollershutterChannel extends DeviceChannel {
31 public RollershutterChannel(final ValueTransformationProvider valueTransformationProvider,
32 final ChannelConfig config) {
33 super(valueTransformationProvider, config);
37 public Optional<String> mapCommand(final Command command) {
40 final String upValue = config.upValue;
41 final String downValue = config.downValue;
42 final String stopValue = config.stopValue;
44 if (command instanceof UpDownType) {
45 if (upValue != null && UpDownType.UP.equals(command)) {
47 } else if (downValue != null && UpDownType.DOWN.equals(command)) {
50 data = command.toFullString();
52 } else if (command instanceof StopMoveType) {
53 if (stopValue != null && StopMoveType.STOP.equals(command)) {
56 data = command.toFullString();
59 data = formatCommand(command);
62 final Optional<String> result = transformCommand(data);
64 logger.debug("Mapped command is '{}'", result.orElse(null));