2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.touchwand.internal;
15 import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.CHANNEL_WALLCONTROLLER_ACTION;
17 import java.time.Instant;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.touchwand.internal.dto.Csc;
21 import org.openhab.binding.touchwand.internal.dto.TouchWandUnitData;
22 import org.openhab.binding.touchwand.internal.dto.TouchWandUnitDataWallController;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
27 * The {@link TouchWandWallControllerHandler} is responsible for handling commands and triggers
29 * for WallController units
31 * @author Roie Geron - Initial contribution
35 public class TouchWandWallControllerHandler extends TouchWandBaseUnitHandler {
37 private long timeLastEventMs;
38 private static final int ADJACENT_EVENT_FILTER_TIME_MILLISEC = 2000; // 2 seconds
40 public TouchWandWallControllerHandler(Thing thing) {
42 timeLastEventMs = Instant.now().toEpochMilli();
46 void touchWandUnitHandleCommand(Command command) {
50 void updateTouchWandUnitState(TouchWandUnitData unitData) {
51 if (unitData instanceof TouchWandUnitDataWallController) {
52 Csc status = ((TouchWandUnitDataWallController) unitData).getCurrStatus();
53 long ts = status.getTs();
54 long timeDiff = ts - timeLastEventMs;
55 if ((timeDiff) > ADJACENT_EVENT_FILTER_TIME_MILLISEC) {
56 int value = status.getKeyAttr();
57 String action = (value <= 100) ? "SHORT" : "LONG";
58 triggerChannel(CHANNEL_WALLCONTROLLER_ACTION, action);
60 timeLastEventMs = status.getTs();
62 logger.debug("updateTouchWandUnitState incompatible TouchWandUnitData instance");