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.neohub.internal;
15 import static org.openhab.binding.neohub.internal.NeoHubBindingConstants.DEBOUNCE_DELAY;
17 import java.util.Date;
18 import java.util.HashMap;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
24 * The {@link NeoHubDebouncer} determines if change events should be forwarded
27 * @author Andrew Fiddian-Green - Initial contribution
30 public class NeoHubDebouncer {
32 private final Map<String, DebounceDelay> channels = new HashMap<>();
34 @SuppressWarnings("null")
36 static class DebounceDelay {
38 private long expireTime;
40 public DebounceDelay(Boolean enabled) {
42 expireTime = new Date().getTime() + (DEBOUNCE_DELAY * 1000);
46 public boolean timeExpired() {
47 return (expireTime < new Date().getTime());
51 public NeoHubDebouncer() {
54 public void initialize(String channelId) {
55 channels.put(channelId, new DebounceDelay(true));
58 @SuppressWarnings("null")
59 public boolean timeExpired(String channelId) {
60 return (channels.containsKey(channelId) ? channels.get(channelId).timeExpired() : true);