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.channelhelper;
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toDateTimeType;
18 import java.time.ZonedDateTime;
19 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
25 import org.openhab.binding.netatmo.internal.api.dto.NAThing;
26 import org.openhab.core.config.core.Configuration;
27 import org.openhab.core.types.State;
30 * The {@link TimestampChannelHelper} handles specific behavior
31 * of modules reporting last seen
33 * @author Gaƫl L'hopital - Initial contribution
37 public class TimestampChannelHelper extends ChannelHelper {
39 public TimestampChannelHelper(Set<String> providedGroups) {
40 super(providedGroups);
44 protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
45 Optional<ZonedDateTime> lastSeen = naThing.getLastSeen();
46 return CHANNEL_LAST_SEEN.equals(channelId) && lastSeen.isPresent() ? toDateTimeType(lastSeen) : null;
50 protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
51 return CHANNEL_MEASURES_TIMESTAMP.equals(channelId) ? toDateTimeType(dashboard.getTimeUtc()) : null;