]> git.basschouten.com Git - openhab-addons.git/blob
6bfdb144b626c90682deda05ffcf5ac15bfe1cb1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.touchwand.internal;
14
15 import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.CHANNEL_SHUTTER;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.touchwand.internal.dto.TouchWandShutterSwitchUnitData;
19 import org.openhab.binding.touchwand.internal.dto.TouchWandUnitData;
20 import org.openhab.core.library.types.PercentType;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.types.Command;
23
24 /**
25  * The {@link TouchWandShutterHandler} is responsible for handling commands for Shutter units
26  *
27  * @author Roie Geron - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public class TouchWandShutterHandler extends TouchWandBaseUnitHandler {
32
33     public TouchWandShutterHandler(Thing thing) {
34         super(thing);
35     }
36
37     @Override
38     void touchWandUnitHandleCommand(Command command) {
39         TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler;
40         if (touchWandBridgeHandler != null) {
41             switch (command.toString()) {
42                 case "OFF":
43                 case "DOWN":
44                     touchWandBridgeHandler.touchWandClient.cmdShutterDown(unitId);
45                     break;
46                 case "ON":
47                 case "UP":
48                     touchWandBridgeHandler.touchWandClient.cmdShutterUp(unitId);
49                     break;
50                 case "STOP":
51                     touchWandBridgeHandler.touchWandClient.cmdShutterStop(unitId);
52                     break;
53                 default:
54                     touchWandBridgeHandler.touchWandClient.cmdShutterPosition(unitId, command.toString());
55                     break;
56             }
57         }
58     }
59
60     @Override
61     void updateTouchWandUnitState(TouchWandUnitData unitData) {
62         if (unitData instanceof TouchWandShutterSwitchUnitData) {
63             int status = ((TouchWandShutterSwitchUnitData) unitData).getCurrStatus();
64             PercentType state = PercentType.ZERO;
65             int convertStatus = 100 - status;
66             state = new PercentType(convertStatus);
67             updateState(CHANNEL_SHUTTER, state);
68         } else {
69             logger.debug("updateTouchWandUnitState incompatible TouchWandUnitData instance");
70         }
71     }
72 }