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.OnOffType;
20 import org.openhab.core.types.Command;
23 * The {@link SwitchChannel} channel provides mappings for the ON and OFF commands
25 * @author Mike Major - Initial contribution
28 public class SwitchChannel extends DeviceChannel {
30 public SwitchChannel(final ValueTransformationProvider valueTransformationProvider, final ChannelConfig config) {
31 super(valueTransformationProvider, config);
35 public Optional<String> mapCommand(final Command command) {
38 final String onValue = config.onValue;
39 final String offValue = config.offValue;
41 if (onValue != null && OnOffType.ON.equals(command)) {
43 } else if (offValue != null && OnOffType.OFF.equals(command)) {
46 data = command.toFullString();
49 final Optional<String> result = transformCommand(data);
51 logger.debug("Mapped command is '{}'", result.orElse(null));