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