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.IncreaseDecreaseType;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.types.Command;
24 * The {@link DimmerChannel} channel applies a format followed by a transform.
26 * @author Mike Major - Initial contribution
29 public class DimmerChannel extends SwitchChannel {
31 public DimmerChannel(final ValueTransformationProvider valueTransformationProvider, final ChannelConfig config) {
32 super(valueTransformationProvider, config);
36 public Optional<String> mapCommand(final Command command) {
37 Optional<String> result;
39 if (command instanceof OnOffType) {
40 result = super.mapCommand(command);
44 final String increaseValue = config.increaseValue;
45 final String decreaseValue = config.decreaseValue;
47 if (command instanceof IncreaseDecreaseType) {
48 if (increaseValue != null && IncreaseDecreaseType.INCREASE.equals(command)) {
50 } else if (decreaseValue != null && IncreaseDecreaseType.DECREASE.equals(command)) {
53 data = command.toFullString();
56 data = formatCommand(command);
59 result = transformCommand(data);
61 logger.debug("Mapped command is '{}'", result.orElse(null));