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