]> git.basschouten.com Git - openhab-addons.git/blob
f25223afd175f9637ec2121963925fd7a94d5ce1
[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.persistence.dynamodb.internal;
14
15 import java.time.ZoneId;
16 import java.time.ZonedDateTime;
17 import java.time.format.DateTimeFormatter;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.persistence.HistoricItem;
21 import org.openhab.core.types.State;
22
23 /**
24  * This is a Java bean used to return historic items from Dynamodb.
25  *
26  * @author Sami Salonen - Initial contribution
27  */
28 @NonNullByDefault
29 public class DynamoDBHistoricItem implements HistoricItem {
30     private static final ZoneId UTC = ZoneId.of("UTC");
31     private static final DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern(DynamoDBItem.DATE_FORMAT)
32             .withZone(UTC);
33
34     private final String name;
35     private final State state;
36     private final ZonedDateTime timestamp;
37
38     public DynamoDBHistoricItem(String name, State state, ZonedDateTime timestamp) {
39         this.name = name;
40         this.state = state;
41         this.timestamp = timestamp;
42     }
43
44     @Override
45     public String getName() {
46         return name;
47     }
48
49     @Override
50     public ZonedDateTime getTimestamp() {
51         return timestamp;
52     }
53
54     @Override
55     public State getState() {
56         return state;
57     }
58
59     @Override
60     public String toString() {
61         return name + ": " + DATEFORMATTER.format(timestamp) + ": " + state.toString();
62     }
63 }