]> git.basschouten.com Git - openhab-addons.git/blob
311a10cd88093751f05356a9a77e0861f13bb492
[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.*;
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.OnOffType;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.types.Command;
23
24 /**
25  * The {@link TouchWandSwitchHandler} is responsible for handling command for Switch unit
26  *
27  *
28  * @author Roie Geron - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class TouchWandSwitchHandler extends TouchWandBaseUnitHandler {
33
34     public TouchWandSwitchHandler(Thing thing) {
35         super(thing);
36     }
37
38     @Override
39     void updateTouchWandUnitState(TouchWandUnitData unitData) {
40         if (unitData instanceof TouchWandShutterSwitchUnitData shutterSwitchUnitData) {
41             OnOffType state;
42             int status = shutterSwitchUnitData.getCurrStatus();
43             String sStatus = Integer.toString(status);
44
45             if (sStatus.equals(SWITCH_STATUS_OFF)) {
46                 state = OnOffType.OFF;
47             } else if ((status >= 1) && (status <= 255)) {
48                 state = OnOffType.ON;
49             } else {
50                 logger.warn("updateTouchWandUnitState illegal update value {}", status);
51                 return;
52             }
53             updateState(CHANNEL_SWITCH, state);
54         } else {
55             logger.debug("updateTouchWandUnitState incompatible TouchWandUnitData instance");
56         }
57     }
58
59     @Override
60     void touchWandUnitHandleCommand(Command command) {
61         if (command instanceof OnOffType onOffCommand) {
62             TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler;
63             if (touchWandBridgeHandler != null) {
64                 touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, onOffCommand);
65             }
66         }
67     }
68 }