]> git.basschouten.com Git - openhab-addons.git/blob
0cc5f56fcb843bcbaa6822ca08143e8d6a18a8eb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.mqtt.ruuvigateway.internal;
14
15 import java.time.Instant;
16 import java.time.ZoneId;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.mqtt.generic.ChannelConfig;
20 import org.openhab.binding.mqtt.generic.ChannelState;
21 import org.openhab.binding.mqtt.generic.values.DateTimeValue;
22 import org.openhab.core.library.types.DateTimeType;
23 import org.openhab.core.thing.ChannelUID;
24
25 /**
26  * Simplified state cache for purposes of caching DateTime values
27  *
28  * Unlike parent class {@link ChannelState}, this class by definition is not interacting with MQTT subscriptions nor
29  * does it update any channels
30  *
31  * @author Sami Salonen - Initial contribution
32  */
33 @NonNullByDefault
34 public class RuuviCachedDateTimeState extends ChannelState {
35
36     private static final ZoneId UTC = ZoneId.of("UTC");
37
38     /**
39      * Construct cache for DateTime values
40      *
41      * @param channelUID associated channel UID
42      *
43      */
44     public RuuviCachedDateTimeState(ChannelUID channelUID) {
45         super(new ChannelConfig(), channelUID, new DateTimeValue(), null);
46     }
47
48     /**
49      * Update cached state with given value
50      *
51      * @param value instant representing value
52      */
53     public void update(Instant value) {
54         cachedValue.update(new DateTimeType(value.atZone(UTC)));
55     }
56 }