]> git.basschouten.com Git - openhab-addons.git/blob
d9340e231d20c10d7281abda7436ae82ef6d5310
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.serial.internal.channel;
14
15 import java.util.Optional;
16
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;
22
23 /**
24  * The {@link RollershutterChannel} channel provides mappings for the UP, DOWN and STOP commands
25  *
26  * @author Mike Major - Initial contribution
27  */
28 @NonNullByDefault
29 public class RollershutterChannel extends DeviceChannel {
30
31     public RollershutterChannel(final ValueTransformationProvider valueTransformationProvider,
32             final ChannelConfig config) {
33         super(valueTransformationProvider, config);
34     }
35
36     @Override
37     public Optional<String> mapCommand(final Command command) {
38         String data;
39
40         final String upValue = config.upValue;
41         final String downValue = config.downValue;
42         final String stopValue = config.stopValue;
43
44         if (command instanceof UpDownType) {
45             if (upValue != null && UpDownType.UP.equals(command)) {
46                 data = upValue;
47             } else if (downValue != null && UpDownType.DOWN.equals(command)) {
48                 data = downValue;
49             } else {
50                 data = command.toFullString();
51             }
52         } else if (command instanceof StopMoveType) {
53             if (stopValue != null && StopMoveType.STOP.equals(command)) {
54                 data = stopValue;
55             } else {
56                 data = command.toFullString();
57             }
58         } else {
59             data = formatCommand(command);
60         }
61
62         final Optional<String> result = transformCommand(data);
63
64         logger.debug("Mapped command is '{}'", result.orElse(null));
65
66         return result;
67     }
68 }