]> git.basschouten.com Git - openhab-addons.git/blob
3ab7173a4cb63f1f4d0377df960b2dc2a6151a56
[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_DIMMER;
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.library.types.PercentType;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.types.Command;
24
25 /**
26  * The {@link TouchWandDimmerHandler} is responsible for handling commands for Dimmer units
27  *
28  * @author Roie Geron - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class TouchWandDimmerHandler extends TouchWandBaseUnitHandler {
33
34     public TouchWandDimmerHandler(Thing thing) {
35         super(thing);
36     }
37
38     @Override
39     void touchWandUnitHandleCommand(Command command) {
40         TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler;
41         if (touchWandBridgeHandler != null) {
42             if (command instanceof OnOffType) {
43                 touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, (OnOffType) command);
44             } else {
45                 touchWandBridgeHandler.touchWandClient.cmdDimmerPosition(unitId, command.toString());
46             }
47         }
48     }
49
50     @Override
51     void updateTouchWandUnitState(TouchWandUnitData unitData) {
52         if (unitData instanceof TouchWandShutterSwitchUnitData) {
53             int status = ((TouchWandShutterSwitchUnitData) unitData).getCurrStatus();
54             PercentType state = PercentType.ZERO;
55             int convertStatus = status;
56             state = new PercentType(convertStatus);
57             updateState(CHANNEL_DIMMER, state);
58         } else {
59             logger.debug("updateTouchWandUnitState incompatible TouchWandUnitData instance");
60         }
61     }
62 }