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.surepetcare.internal.handler;
15 import static org.openhab.core.thing.ThingStatus.ONLINE;
17 import java.time.Duration;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.surepetcare.internal.SurePetcareAPIHelper;
23 import org.openhab.core.cache.ExpiringCache;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.binding.BaseThingHandler;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.RefreshType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link SurePetcareBaseObjectHandler} is responsible for handling the things created to represent Sure Petcare
36 * @author Rene Scherer - Initial Contribution
39 public abstract class SurePetcareBaseObjectHandler extends BaseThingHandler {
41 private static final int CACHE_TIMEOUT_SECOND = 3;
43 private final Logger logger = LoggerFactory.getLogger(SurePetcareBaseObjectHandler.class);
45 protected final SurePetcareAPIHelper petcareAPI;
47 protected ExpiringCache<Integer> updateThingCache = new ExpiringCache<>(Duration.ofSeconds(CACHE_TIMEOUT_SECOND),
50 public SurePetcareBaseObjectHandler(Thing thing, final SurePetcareAPIHelper petcareAPI) {
52 this.petcareAPI = petcareAPI;
56 public void initialize() {
61 public void handleCommand(ChannelUID channelUID, Command command) {
62 if (command instanceof RefreshType) {
63 updateThingCache.getValue();
68 public void updateProperties(@Nullable Map<String, String> properties) {
69 super.updateProperties(properties);
72 private @Nullable Integer refreshCache() {
73 logger.debug("cache has timed out, we refresh the values in the thing");
75 // we don't care about the cache content, we just return an empty object
76 return Integer.MIN_VALUE;
80 * Updates all channels of a thing.
82 protected abstract void updateThing();