]> git.basschouten.com Git - openhab-addons.git/blob
32c3e371b95941434586898affbfd9e3acd171a4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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_WALLCONTROLLER_ACTION;
16
17 import java.time.Instant;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.touchwand.internal.dto.TouchWandUnitData;
21 import org.openhab.binding.touchwand.internal.dto.TouchWandUnitDataWallController;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.types.Command;
24
25 /**
26  * The {@link TouchWandWallControllerHandler} is responsible for handling commands and triggers
27  *
28  * for WallController units
29  *
30  * @author Roie Geron - Initial contribution
31  *
32  */
33 @NonNullByDefault
34 public class TouchWandWallControllerHandler extends TouchWandBaseUnitHandler {
35
36     private long timeSinceLastEventMs;
37     private static final int ADJUSTENT_EVENT_FILTER_TIME_MILLISEC = 2000; // 2 seconds
38
39     public TouchWandWallControllerHandler(Thing thing) {
40         super(thing);
41         timeSinceLastEventMs = Instant.now().toEpochMilli();
42     }
43
44     @Override
45     void touchWandUnitHandleCommand(Command command) {
46     }
47
48     @Override
49     void updateTouchWandUnitState(TouchWandUnitData unitData) {
50         int status = ((TouchWandUnitDataWallController) unitData).getCurrStatus();
51         long timeDiff = Instant.now().toEpochMilli() - timeSinceLastEventMs;
52         if ((timeDiff) > ADJUSTENT_EVENT_FILTER_TIME_MILLISEC) {
53             String action = status <= 100 ? "SHORT" : "LONG";
54             triggerChannel(CHANNEL_WALLCONTROLLER_ACTION, action);
55         }
56         timeSinceLastEventMs = Instant.now().toEpochMilli();
57     }
58 }