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.siemensrds.internal;
15 import static org.openhab.binding.siemensrds.internal.RdsBindingConstants.DEBOUNCE_DELAY;
17 import java.util.Date;
18 import java.util.HashMap;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
24 * The {@link RdsDebouncer} determines if change events should be forwarded to a
27 * @author Andrew Fiddian-Green - Initial contribution
30 public class RdsDebouncer {
32 private final Map<String, DebounceDelay> channels = new HashMap<>();
34 static class DebounceDelay {
36 private long expireTime;
38 public DebounceDelay(boolean enabled) {
40 expireTime = new Date().getTime() + (DEBOUNCE_DELAY * 1000);
44 public boolean timeExpired() {
45 return (expireTime < new Date().getTime());
49 public RdsDebouncer() {
52 public void initialize(String channelId) {
53 channels.put(channelId, new DebounceDelay(true));
56 public Boolean timeExpired(String channelId) {
57 if (channels.containsKey(channelId)) {
58 DebounceDelay debounceDelay = channels.get(channelId);
59 if (debounceDelay != null) {
60 return debounceDelay.timeExpired();