2 * Copyright (c) 2010-2024 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.netatmo.internal.handler.capability;
15 import java.util.Optional;
16 import java.util.concurrent.ScheduledFuture;
17 import java.util.concurrent.TimeUnit;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * {@link ParentUpdateCapability} is the class used to request data update upon initialization of a module
27 * @author Gaƫl L'hopital - Initial contribution
31 public class ParentUpdateCapability extends Capability {
32 private static final int DEFAULT_DELAY_S = 2;
34 private final Logger logger = LoggerFactory.getLogger(ParentUpdateCapability.class);
35 private Optional<ScheduledFuture<?>> job = Optional.empty();
37 public ParentUpdateCapability(CommonInterface handler) {
42 public void initialize() {
43 job = Optional.of(handler.getScheduler().schedule(() -> {
44 logger.debug("Requesting parents data update for Thing {}", handler.getId());
45 CommonInterface bridgeHandler = handler.getBridgeHandler();
46 if (bridgeHandler != null) {
47 bridgeHandler.expireData();
49 }, DEFAULT_DELAY_S, TimeUnit.SECONDS));
53 public void dispose() {
54 job.ifPresent(j -> j.cancel(true));
55 job = Optional.empty();