]> git.basschouten.com Git - openhab-addons.git/blob
e58df03c0a11c4094c49cfd258a48246b0334b60
[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.semsportal.internal.dto;
14
15 import java.time.Instant;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
18 import java.time.format.DateTimeFormatter;
19 import java.time.format.DateTimeFormatterBuilder;
20 import java.util.List;
21
22 import org.openhab.binding.semsportal.internal.SEMSPortalBindingConstants;
23
24 import com.google.gson.annotations.SerializedName;
25
26 /**
27  * Facade for easy access to the SEMS portal data response. Data is distributed over different parts of the response
28  * object
29  *
30  * @author Iwan Bron - Initial contribution
31  */
32 public class StationStatus {
33     @SerializedName("kpi")
34     private KeyPerformanceIndicators keyPerformanceIndicators;
35     @SerializedName("inverter")
36     private List<Station> stations;
37     @SerializedName("info")
38     private StationInfo info;
39
40     public Double getCurrentOutput() {
41         return keyPerformanceIndicators.getCurrentOutput();
42     }
43
44     public Double getDayTotal() {
45         return stations.isEmpty() ? null : stations.get(0).getDayTotal();
46     }
47
48     public Double getMonthTotal() {
49         return stations.isEmpty() ? null : stations.get(0).getMonthTotal();
50     }
51
52     public Double getOverallTotal() {
53         return stations.isEmpty() ? null : stations.get(0).getOverallTotal();
54     }
55
56     public Double getDayIncome() {
57         return keyPerformanceIndicators.getDayIncome();
58     }
59
60     public Double getTotalIncome() {
61         return keyPerformanceIndicators.getTotalIncome();
62     }
63
64     public boolean isOperational() {
65         return stations.isEmpty() ? false : stations.get(0).getStatus() == 1;
66     }
67
68     public ZonedDateTime getLastUpdate() {
69         if (stations.isEmpty()) {
70             return null;
71         }
72         DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern(info.getDateFormat())
73                 .appendLiteral(" ").appendPattern(SEMSPortalBindingConstants.TIME_FORMAT).toFormatter()
74                 .withZone(ZoneId.systemDefault());
75         Instant instant = formatter.parse(stations.get(0).getDetails().getLastUpdate(), Instant::from);
76         return ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
77     }
78 }