]> git.basschouten.com Git - openhab-addons.git/blob
26ca297b68c55e952ec5483920b4a6528dc762af
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.netatmo.internal.handler.channelhelper;
14
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toDateTimeType;
17
18 import java.time.ZonedDateTime;
19 import java.util.Optional;
20 import java.util.Set;
21
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;
28
29 /**
30  * The {@link TimestampChannelHelper} handles specific behavior
31  * of modules reporting last seen
32  *
33  * @author GaĆ«l L'hopital - Initial contribution
34  *
35  */
36 @NonNullByDefault
37 public class TimestampChannelHelper extends ChannelHelper {
38
39     public TimestampChannelHelper(Set<String> providedGroups) {
40         super(providedGroups);
41     }
42
43     @Override
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;
47     }
48
49     @Override
50     protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
51         return CHANNEL_MEASURES_TIMESTAMP.equals(channelId) ? toDateTimeType(dashboard.getTimeUtc()) : null;
52     }
53 }