2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.semsportal.internal.dto;
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;
22 import org.openhab.binding.semsportal.internal.SEMSPortalBindingConstants;
24 import com.google.gson.annotations.SerializedName;
27 * Facade for easy access to the SEMS portal data response. Data is distributed over different parts of the response
30 * @author Iwan Bron - Initial contribution
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;
40 public Double getCurrentOutput() {
41 return keyPerformanceIndicators.getCurrentOutput();
44 public Double getDayTotal() {
45 return stations.isEmpty() ? null : stations.get(0).getDayTotal();
48 public Double getMonthTotal() {
49 return stations.isEmpty() ? null : stations.get(0).getMonthTotal();
52 public Double getOverallTotal() {
53 return stations.isEmpty() ? null : stations.get(0).getOverallTotal();
56 public Double getDayIncome() {
57 return keyPerformanceIndicators.getDayIncome();
60 public Double getTotalIncome() {
61 return keyPerformanceIndicators.getTotalIncome();
64 public boolean isOperational() {
65 return stations.isEmpty() ? false : stations.get(0).getStatus() == 1;
68 public ZonedDateTime getLastUpdate() {
69 if (stations.isEmpty()) {
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());