]> git.basschouten.com Git - openhab-addons.git/blob
8c8dbba725578f887b91bcf7c08c3fc523d9d54c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.netatmo.internal.api.dto.NAThing;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.types.State;
26
27 /**
28  * The {@link TimestampChannelHelper} handles specific behavior
29  * of modules reporting last seen
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class TimestampChannelHelper extends ChannelHelper {
36
37     public TimestampChannelHelper() {
38         this(GROUP_TIMESTAMP);
39     }
40
41     protected TimestampChannelHelper(String groupName) {
42         super(groupName);
43     }
44
45     @Override
46     protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
47         Optional<ZonedDateTime> lastSeen = naThing.getLastSeen();
48         return CHANNEL_LAST_SEEN.equals(channelId) && lastSeen.isPresent() ? toDateTimeType(lastSeen) : null;
49     }
50 }