]> git.basschouten.com Git - openhab-addons.git/blob
acf0629d828806d0e9e795ae71f6752803a0bffb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.regoheatpump.internal.rego6xx;
14
15 import java.time.ZoneId;
16 import java.time.ZonedDateTime;
17
18 /**
19  * The {@link ErrorLine} is responsible for holding information about a single error line.
20  *
21  * @author Boris Krivonog - Initial contribution
22  */
23 public class ErrorLine {
24     private final byte error;
25     private final String timestamp;
26
27     public ErrorLine(byte error, String timestamp) {
28         this.error = error;
29         this.timestamp = timestamp;
30     }
31
32     @Override
33     public String toString() {
34         return String.format("%d @ %s", error, timestamp);
35     }
36
37     public byte error() {
38         return error;
39     }
40
41     public String timestampAsString() {
42         return timestamp;
43     }
44
45     public ZonedDateTime timestamp() {
46         int year = Integer.parseInt(timestamp.substring(0, 2)) + 1000;
47         if (year < 1950) {
48             year += 1000;
49         }
50         int month = Integer.parseInt(timestamp.substring(2, 4));
51         int day = Integer.parseInt(timestamp.substring(4, 6));
52         int hour = Integer.parseInt(timestamp.substring(7, 9));
53         int min = Integer.parseInt(timestamp.substring(10, 12));
54         int sec = Integer.parseInt(timestamp.substring(13, 15));
55
56         return ZonedDateTime.of(year, month, day, hour, min, sec, 0, ZoneId.systemDefault());
57     }
58 }