From: Florian Hotze Date: Thu, 25 Jul 2024 07:47:22 +0000 (+0200) Subject: [fronius] Improve package structure & Enhance null annotations/handling (#17109) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=1fedd7ad428fe2c5000d13b0e26a2541dbd416dc;p=openhab-addons.git [fronius] Improve package structure & Enhance null annotations/handling (#17109) * [fronius] Restructure DTOs & Improve null annotations/handling Signed-off-by: Florian Hotze --- diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java index f704e47ac5..047afd13f2 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusBindingConstants.java @@ -103,6 +103,8 @@ public class FroniusBindingConstants { public static final String METER_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%&DataCollection=MeterRealtimeData"; public static final String OHMPILOT_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetOhmPilotRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%"; + public static final int API_TIMEOUT = 5000; + public static String getInverterDataUrl(String ip, int deviceId) { return parseUrl(INVERTER_REALTIME_DATA_URL, ip, deviceId); } @@ -120,7 +122,7 @@ public class FroniusBindingConstants { } public static String parseUrl(String url, String ip) { - return url.replace("%IP%", ip == null ? "" : ip.trim()); + return url.replace("%IP%", ip.trim()); } public static String parseUrl(String url, String ip, int deviceId) { diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusCommunicationException.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusCommunicationException.java deleted file mode 100644 index 205bff6fc1..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusCommunicationException.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal; - -import java.io.IOException; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * Exception for unexpected response from or communication failure with the Fronius controller. - * - * @author Jimmy Tanagra - Initial contribution - */ -@NonNullByDefault -public class FroniusCommunicationException extends IOException { - private static final long serialVersionUID = 619020705591964155L; - - public FroniusCommunicationException(String message) { - super(message); - } - - public FroniusCommunicationException(Throwable ex) { - super(ex); - } - - public FroniusCommunicationException(String message, @Nullable Throwable cause) { - super(message, cause); - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHttpUtil.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHttpUtil.java deleted file mode 100644 index 9ae3a76659..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/FroniusHttpUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal; - -import java.io.IOException; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.io.net.http.HttpUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * A version of HttpUtil implementation that retries on failure - * - * @author Jimmy Tanagra - Initial contribution - * - */ -@NonNullByDefault -public class FroniusHttpUtil { - private static final Logger logger = LoggerFactory.getLogger(FroniusHttpUtil.class); - - /** - * Issue a HTTP GET request and retry on failure - * - * @param url the url to execute - * @param timeout the socket timeout in milliseconds to wait for data - * @return the response body - * @throws FroniusCommunicationException when the request execution failed or interrupted - */ - public static synchronized String executeUrl(String url, int timeout) throws FroniusCommunicationException { - int attemptCount = 1; - try { - while (true) { - Throwable lastException = null; - String result = null; - try { - result = HttpUtil.executeUrl("GET", url, timeout); - } catch (IOException e) { - // HttpUtil::executeUrl wraps InterruptedException into IOException. - // Unwrap and rethrow it so that we don't retry on InterruptedException - if (e.getCause() instanceof InterruptedException) { - throw (InterruptedException) e.getCause(); - } - lastException = e; - } - - if (result != null) { - if (attemptCount > 1) { - logger.debug("Attempt #{} successful {}", attemptCount, url); - } - return result; - } - - if (attemptCount >= 3) { - logger.debug("Failed connecting to {} after {} attempts.", url, attemptCount, lastException); - throw new FroniusCommunicationException("Unable to connect", lastException); - } - - logger.debug("HTTP error on attempt #{} {}", attemptCount, url); - Thread.sleep(500 * attemptCount); - attemptCount++; - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new FroniusCommunicationException("Interrupted", e); - } - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/BaseFroniusResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/BaseFroniusResponse.java deleted file mode 100644 index 10ce051faa..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/BaseFroniusResponse.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * base class for a response-object from the API - * - * @author Thomas Rokohl - Initial contribution - */ -public class BaseFroniusResponse { - @SerializedName("Head") - private Head head; - - public Head getHead() { - if (head == null) { - head = new Head(); - } - return head; - } - - public void setHead(Head head) { - this.head = head; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/DeviceStatus.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/DeviceStatus.java deleted file mode 100644 index d7d44cd0cc..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/DeviceStatus.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link DeviceStatus} is responsible for storing - * the "devicestatus" node - * - * @author Thomas Rokohl - Initial contribution - */ -public class DeviceStatus { - @SerializedName("StatusCode") - private int statusCode; - @SerializedName("MgmtTimerRemainingTime") - private int mgmtTimerRemainingTime; - @SerializedName("ErrorCode") - private int errorCode; - @SerializedName("LEDColor") - private int ledColor; - @SerializedName("LEDState") - private int ledState; - @SerializedName("StateToReset") - private boolean stateToReset; - - public int getStatusCode() { - return statusCode; - } - - public void setStatusCode(int statusCode) { - this.statusCode = statusCode; - } - - public int getMgmtTimerRemainingTime() { - return mgmtTimerRemainingTime; - } - - public void setMgmtTimerRemainingTime(int mgmtTimerRemainingTime) { - this.mgmtTimerRemainingTime = mgmtTimerRemainingTime; - } - - public int getErrorCode() { - return errorCode; - } - - public void setErrorCode(int errorCode) { - this.errorCode = errorCode; - } - - public int getLedColor() { - return ledColor; - } - - public void setLedColor(int ledColor) { - this.ledColor = ledColor; - } - - public int getLedState() { - return ledState; - } - - public void setLedState(int ledState) { - this.ledState = ledState; - } - - public boolean isStateToReset() { - return stateToReset; - } - - public void setStateToReset(boolean stateToReset) { - this.stateToReset = stateToReset; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusCommunicationException.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusCommunicationException.java new file mode 100644 index 0000000000..25c1d3ed2b --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusCommunicationException.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import java.io.IOException; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * Exception for unexpected response from or communication failure with the Fronius controller. + * + * @author Jimmy Tanagra - Initial contribution + */ +@NonNullByDefault +public class FroniusCommunicationException extends IOException { + private static final long serialVersionUID = 619020705591964155L; + + public FroniusCommunicationException(String message) { + super(message); + } + + public FroniusCommunicationException(Throwable ex) { + super(ex); + } + + public FroniusCommunicationException(String message, @Nullable Throwable cause) { + super(message, cause); + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusHttpUtil.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusHttpUtil.java new file mode 100644 index 0000000000..ccc26119a4 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusHttpUtil.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api; + +import java.io.IOException; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jetty.http.HttpMethod; +import org.openhab.core.io.net.http.HttpUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * A version of HttpUtil implementation that retries on failure. + * + * @author Jimmy Tanagra - Initial contribution + * + */ +@NonNullByDefault +public class FroniusHttpUtil { + private static final Logger logger = LoggerFactory.getLogger(FroniusHttpUtil.class); + + /** + * Issue a HTTP request and retry on failure. + * + * @param httpMethod the HTTP method to use + * @param url the url to execute + * @param timeout the socket timeout in milliseconds to wait for data + * @return the response body + * @throws FroniusCommunicationException when the request execution failed or interrupted + */ + public static synchronized String executeUrl(HttpMethod httpMethod, String url, int timeout) + throws FroniusCommunicationException { + int attemptCount = 1; + try { + while (true) { + Throwable lastException = null; + String result = null; + try { + result = HttpUtil.executeUrl(httpMethod.asString(), url, timeout); + } catch (IOException e) { + // HttpUtil::executeUrl wraps InterruptedException into IOException. + // Unwrap and rethrow it so that we don't retry on InterruptedException + Throwable cause = e.getCause(); + if (cause instanceof InterruptedException interruptException) { + throw interruptException; + } + lastException = e; + } + + if (result != null) { + if (attemptCount > 1) { + logger.debug("Attempt #{} successful {}", attemptCount, url); + } + return result; + } + + if (attemptCount >= 3) { + logger.debug("Failed connecting to {} after {} attempts.", url, attemptCount, lastException); + throw new FroniusCommunicationException("Unable to connect", lastException); + } + + logger.debug("HTTP error on attempt #{} {}", attemptCount, url); + Thread.sleep(500 * attemptCount); + attemptCount++; + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new FroniusCommunicationException("Interrupted", e); + } + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/Head.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/Head.java deleted file mode 100644 index e99f3f045e..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/Head.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link Head} is responsible for storing - * the "head" node of the JSON response from the Fronius Solar APIs (V1) - * - * The contents of the response object will vary depending on the preceding request but it always contains a common - * response header and a request body. - * - * @author Thomas Rokohl - Initial contribution - */ -public class Head { - @SerializedName("RequestArguments") - private HeadRequestArguments requestArguments; - @SerializedName("Status") - private HeadStatus status; - @SerializedName("Timestamp") - private String timestamp; - - public HeadRequestArguments getRequestArguments() { - if (requestArguments == null) { - requestArguments = new HeadRequestArguments(); - } - return requestArguments; - } - - public void setRequestArguments(HeadRequestArguments requestArguments) { - this.requestArguments = requestArguments; - } - - public HeadStatus getStatus() { - if (status == null) { - status = new HeadStatus(); - status.setCode(255); - status.setReason("undefined runtime error"); - } - return status; - } - - public void setStatus(HeadStatus status) { - this.status = status; - } - - public String getTimestamp() { - if (timestamp == null) { - timestamp = ""; - } - return timestamp; - } - - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadRequestArguments.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadRequestArguments.java deleted file mode 100644 index 1476294d4b..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadRequestArguments.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link HeadRequestArguments} is responsible for storing - * the "RequestArguments" node from the {@link Head} - * - * @author Thomas Rokohl - Initial contribution - */ -public class HeadRequestArguments { - @SerializedName("DataCollection") - private String dataCollection; - @SerializedName("DeviceClass") - private String deviceClass; - @SerializedName("DeviceId") - private String deviceId; - @SerializedName("Scope") - private String scope; - - public String getDataCollection() { - if (null == dataCollection) { - dataCollection = ""; - } - return dataCollection; - } - - public void setDataCollection(String dataCollection) { - this.dataCollection = dataCollection; - } - - public String getDeviceClass() { - if (null == deviceClass) { - deviceClass = ""; - } - return deviceClass; - } - - public void setDeviceClass(String deviceClass) { - this.deviceClass = deviceClass; - } - - public String getDeviceId() { - if (null == deviceId) { - deviceId = ""; - } - return deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getScope() { - if (null == scope) { - scope = ""; - } - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadStatus.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadStatus.java deleted file mode 100644 index 34a404211c..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/HeadStatus.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link HeadStatus} is responsible for storing - * the "status" node from the {@link Head} - * - * @author Thomas Rokohl - Initial contribution - */ -public class HeadStatus { - @SerializedName("Code") - private int code; - @SerializedName("Reason") - private String reason; - @SerializedName("UserMessage") - private String userMessage; - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getReason() { - if (reason == null) { - reason = ""; - } - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public String getUserMessage() { - if (userMessage == null) { - userMessage = ""; - } - return userMessage; - } - - public void setUserMessage(String userMessage) { - this.userMessage = userMessage; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBody.java deleted file mode 100644 index 94cff01e28..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBody.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link InverterRealtimeBody} is responsible for storing - * the "body" node of the JSON response - * - * @author Thomas Rokohl - Initial contribution - */ -public class InverterRealtimeBody { - @SerializedName("Data") - private InverterRealtimeBodyData data; - - public InverterRealtimeBodyData getData() { - if (data == null) { - data = new InverterRealtimeBodyData(); - } - return data; - } - - public void setData(InverterRealtimeBodyData data) { - this.data = data; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBodyData.java deleted file mode 100644 index 65898d3787..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeBodyData.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link InverterRealtimeBodyData} is responsible for storing - * the "data" node of the JSON response - * - * @author Thomas Rokohl - Initial contribution - */ -public class InverterRealtimeBodyData { - - @SerializedName("DAY_ENERGY") - private ValueUnit dayEnergy; - @SerializedName("FAC") - private ValueUnit fac; - @SerializedName("IAC") - private ValueUnit iac; - @SerializedName("IDC") - private ValueUnit idc; - @SerializedName("IDC_2") - private ValueUnit idc2; - @SerializedName("IDC_3") - private ValueUnit idc3; - @SerializedName("PAC") - private ValueUnit pac; - @SerializedName("TOTAL_ENERGY") - private ValueUnit totalEnergy; - @SerializedName("UAC") - private ValueUnit uac; - @SerializedName("UDC") - private ValueUnit udc; - @SerializedName("UDC_2") - private ValueUnit udc2; - @SerializedName("UDC_3") - private ValueUnit udc3; - @SerializedName("YEAR_ENERGY") - private ValueUnit yearEnergy; - @SerializedName("DeviceStatus") - private DeviceStatus deviceStatus; - - public ValueUnit getDayEnergy() { - return dayEnergy; - } - - public void setDayEnergy(ValueUnit dayEnergy) { - this.dayEnergy = dayEnergy; - } - - public ValueUnit getPac() { - return pac; - } - - public void setPac(ValueUnit pac) { - this.pac = pac; - } - - public ValueUnit getTotalEnergy() { - return totalEnergy; - } - - public void setTotalEnergy(ValueUnit totalEnergy) { - this.totalEnergy = totalEnergy; - } - - public ValueUnit getYearEnergy() { - return yearEnergy; - } - - public void setYearEnergy(ValueUnit yearEnergy) { - this.yearEnergy = yearEnergy; - } - - public DeviceStatus getDeviceStatus() { - if (deviceStatus == null) { - deviceStatus = new DeviceStatus(); - } - return deviceStatus; - } - - public void setDeviceStatus(DeviceStatus deviceStatus) { - this.deviceStatus = deviceStatus; - } - - public ValueUnit getFac() { - return fac; - } - - public void setFac(ValueUnit fac) { - this.fac = fac; - } - - public ValueUnit getIac() { - return iac; - } - - public void setIac(ValueUnit iac) { - this.iac = iac; - } - - public ValueUnit getIdc() { - return idc; - } - - public void setIdc(ValueUnit idc) { - this.idc = idc; - } - - public ValueUnit getIdc2() { - return idc2; - } - - public ValueUnit getIdc3() { - return idc3; - } - - public ValueUnit getUac() { - return uac; - } - - public void setUac(ValueUnit uac) { - this.uac = uac; - } - - public ValueUnit getUdc() { - return udc; - } - - public void setUdc(ValueUnit udc) { - this.udc = udc; - } - - public ValueUnit getUdc2() { - return udc2; - } - - public ValueUnit getUdc3() { - return udc3; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeResponse.java deleted file mode 100644 index dd12bed50c..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/InverterRealtimeResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link InverterRealtimeResponse} is responsible for storing - * the response from the realtime api - * - * @author Thomas Rokohl - Initial contribution - */ -public class InverterRealtimeResponse extends BaseFroniusResponse { - - @SerializedName("Body") - private InverterRealtimeBody body; - - public InverterRealtimeBody getBody() { - if (body == null) { - body = new InverterRealtimeBody(); - } - return body; - } - - public void setBody(InverterRealtimeBody body) { - this.body = body; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDTO.java deleted file mode 100644 index 4c9560b398..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link MeterRealtimeBodyDTO} is responsible for storing - * the "body" node of the JSON response - * - * @author Jimmy Tanagra - Initial contribution - */ -public class MeterRealtimeBodyDTO { - @SerializedName("Data") - private MeterRealtimeBodyDataDTO data; - - public MeterRealtimeBodyDataDTO getData() { - if (data == null) { - data = new MeterRealtimeBodyDataDTO(); - } - return data; - } - - public void setData(MeterRealtimeBodyDataDTO data) { - this.data = data; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDataDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDataDTO.java deleted file mode 100644 index de4b636184..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeBodyDataDTO.java +++ /dev/null @@ -1,403 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link MeterRealtimeBodyDataDTO} is responsible for storing - * the "data" node of the JSON response - * - * The main SerializedName values use Smart Meter 63A names - * The first SerializedName alternate names use Smart Meter 65A names - * - * @author Jimmy Tanagra - Initial contribution - */ -public class MeterRealtimeBodyDataDTO { - @SerializedName(value = "Current_AC_Phase_1", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_01_F32" }) - private double currentACPhase1; - @SerializedName(value = "Current_AC_Phase_2", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_02_F32" }) - private double currentACPhase2; - @SerializedName(value = "Current_AC_Phase_3", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_03_F32" }) - private double currentACPhase3; - @SerializedName("Details") - private MeterRealtimeDetailsDTO details; - @SerializedName(value = "Enable", alternate = { "COMPONENTS_MODE_ENABLE_U16" }) - private int enable; - @SerializedName(value = "EnergyReactive_VArAC_Sum_Consumed", alternate = { - "SMARTMETER_ENERGYREACTIVE_CONSUMED_SUM_F64" }) - private double energyReactiveVArACSumConsumed; - @SerializedName(value = "EnergyReactive_VArAC_Sum_Produced", alternate = { - "SMARTMETER_ENERGYREACTIVE_PRODUCED_SUM_F64" }) - private double energyReactiveVArACSumProduced; - @SerializedName(value = "EnergyReal_WAC_Minus_Absolute", alternate = { - "SMARTMETER_ENERGYACTIVE_ABSOLUT_MINUS_F64" }) - private double energyRealWACMinusAbsolute; - @SerializedName(value = "EnergyReal_WAC_Plus_Absolute", alternate = { "SMARTMETER_ENERGYACTIVE_ABSOLUT_PLUS_F64" }) - private double energyRealWACPlusAbsolute; - @SerializedName(value = "EnergyReal_WAC_Sum_Consumed", alternate = { "SMARTMETER_ENERGYACTIVE_CONSUMED_SUM_F64" }) - private double energyRealWACSumConsumed; - @SerializedName(value = "EnergyReal_WAC_Sum_Produced", alternate = { "SMARTMETER_ENERGYACTIVE_PRODUCED_SUM_F64" }) - private double energyRealWACSumProduced; - @SerializedName(value = "Frequency_Phase_Average", alternate = { "GRID_FREQUENCY_MEAN_F32" }) - private double frequencyPhaseAverage; - @SerializedName(value = "Meter_Location_Current", alternate = { "SMARTMETER_VALUE_LOCATION_U16" }) - private int meterLocationCurrent; - @SerializedName(value = "PowerApparent_S_Phase_1", alternate = { "SMARTMETER_POWERAPPARENT_01_F64" }) - private double powerApparentSPhase1; - @SerializedName(value = "PowerApparent_S_Phase_2", alternate = { "SMARTMETER_POWERAPPARENT_02_F64" }) - private double powerApparentSPhase2; - @SerializedName(value = "PowerApparent_S_Phase_3", alternate = { "SMARTMETER_POWERAPPARENT_03_F64" }) - private double powerApparentSPhase3; - @SerializedName(value = "PowerApparent_S_Sum", alternate = { "SMARTMETER_POWERAPPARENT_MEAN_SUM_F64" }) - private double powerApparentSSum; - @SerializedName(value = "PowerFactor_Phase_1", alternate = { "SMARTMETER_FACTOR_POWER_01_F64" }) - private double powerFactorPhase1; - @SerializedName(value = "PowerFactor_Phase_2", alternate = { "SMARTMETER_FACTOR_POWER_02_F64" }) - private double powerFactorPhase2; - @SerializedName(value = "PowerFactor_Phase_3", alternate = { "SMARTMETER_FACTOR_POWER_03_F64" }) - private double powerFactorPhase3; - @SerializedName(value = "PowerFactor_Sum", alternate = { "SMARTMETER_FACTOR_POWER_SUM_F64" }) - private double powerFactorSum; - @SerializedName(value = "PowerReactive_Q_Phase_1", alternate = { "SMARTMETER_POWERREACTIVE_01_F64" }) - private double powerReactiveQPhase1; - @SerializedName(value = "PowerReactive_Q_Phase_2", alternate = { "SMARTMETER_POWERREACTIVE_02_F64" }) - private double powerReactiveQPhase2; - @SerializedName(value = "PowerReactive_Q_Phase_3", alternate = { "SMARTMETER_POWERREACTIVE_03_F64" }) - private double powerReactiveQPhase3; - @SerializedName(value = "PowerReactive_Q_Sum", alternate = { "SMARTMETER_POWERREACTIVE_MEAN_SUM_F64" }) - private double powerReactiveQSum; - @SerializedName(value = "PowerReal_P_Phase_1", alternate = { "SMARTMETER_POWERACTIVE_01_F64" }) - private double powerRealPPhase1; - @SerializedName(value = "PowerReal_P_Phase_2", alternate = { "SMARTMETER_POWERACTIVE_02_F64" }) - private double powerRealPPhase2; - @SerializedName(value = "PowerReal_P_Phase_3", alternate = { "SMARTMETER_POWERACTIVE_03_F64" }) - private double powerRealPPhase3; - @SerializedName(value = "PowerReal_P_Sum", alternate = { "SMARTMETER_POWERACTIVE_MEAN_SUM_F64" }) - private double powerRealPSum; - @SerializedName("TimeStamp") - private int timeStamp; - @SerializedName(value = "Visible", alternate = { "COMPONENTS_MODE_VISIBLE_U16" }) - private int visible; - @SerializedName(value = "Voltage_AC_PhaseToPhase_12", alternate = { "ACBRIDGE_VOLTAGE_MEAN_12_F32" }) - private double voltageACPhaseToPhase12; - @SerializedName(value = "Voltage_AC_PhaseToPhase_23", alternate = { "ACBRIDGE_VOLTAGE_MEAN_23_F32" }) - private double voltageACPhaseToPhase23; - @SerializedName(value = "Voltage_AC_PhaseToPhase_31", alternate = { "ACBRIDGE_VOLTAGE_MEAN_31_F32" }) - private double voltageACPhaseToPhase31; - @SerializedName(value = "Voltage_AC_Phase_1", alternate = { "SMARTMETER_VOLTAGE_01_F64" }) - private double voltageACPhase1; - @SerializedName(value = "Voltage_AC_Phase_2", alternate = { "SMARTMETER_VOLTAGE_02_F64" }) - private double voltageACPhase2; - @SerializedName(value = "Voltage_AC_Phase_3", alternate = { "SMARTMETER_VOLTAGE_03_F64" }) - private double voltageACPhase3; - - public double getCurrentACPhase1() { - return currentACPhase1; - } - - public void setCurrentACPhase1(double currentACPhase1) { - this.currentACPhase1 = currentACPhase1; - } - - public double getCurrentACPhase2() { - return currentACPhase2; - } - - public void setCurrentACPhase2(double currentACPhase2) { - this.currentACPhase2 = currentACPhase2; - } - - public double getCurrentACPhase3() { - return currentACPhase3; - } - - public void setCurrentACPhase3(double currentACPhase3) { - this.currentACPhase3 = currentACPhase3; - } - - public MeterRealtimeDetailsDTO getDetails() { - if (details == null) { - details = new MeterRealtimeDetailsDTO(); - } - return details; - } - - public void setDetails(MeterRealtimeDetailsDTO details) { - this.details = details; - } - - public int getEnable() { - return enable; - } - - public void setEnable(int enable) { - this.enable = enable; - } - - public double getEnergyReactiveVArACSumConsumed() { - return energyReactiveVArACSumConsumed; - } - - public void setEnergyReactiveVArACSumConsumed(double energyReactiveVArACSumConsumed) { - this.energyReactiveVArACSumConsumed = energyReactiveVArACSumConsumed; - } - - public double getEnergyReactiveVArACSumProduced() { - return energyReactiveVArACSumProduced; - } - - public void setEnergyReactiveVArACSumProduced(double energyReactiveVArACSumProduced) { - this.energyReactiveVArACSumProduced = energyReactiveVArACSumProduced; - } - - public double getEnergyRealWACMinusAbsolute() { - return energyRealWACMinusAbsolute; - } - - public void setEnergyRealWACMinusAbsolute(double energyRealWACMinusAbsolute) { - this.energyRealWACMinusAbsolute = energyRealWACMinusAbsolute; - } - - public double getEnergyRealWACPlusAbsolute() { - return energyRealWACPlusAbsolute; - } - - public void setEnergyRealWACPlusAbsolute(double energyRealWACPlusAbsolute) { - this.energyRealWACPlusAbsolute = energyRealWACPlusAbsolute; - } - - public double getEnergyRealWACSumConsumed() { - return energyRealWACSumConsumed; - } - - public void setEnergyRealWACSumConsumed(double energyRealWACSumConsumed) { - this.energyRealWACSumConsumed = energyRealWACSumConsumed; - } - - public double getEnergyRealWACSumProduced() { - return energyRealWACSumProduced; - } - - public void setEnergyRealWACSumProduced(double energyRealWACSumProduced) { - this.energyRealWACSumProduced = energyRealWACSumProduced; - } - - public double getFrequencyPhaseAverage() { - return frequencyPhaseAverage; - } - - public void setFrequencyPhaseAverage(double frequencyPhaseAverage) { - this.frequencyPhaseAverage = frequencyPhaseAverage; - } - - public int getMeterLocationCurrent() { - return meterLocationCurrent; - } - - public void setMeterLocationCurrent(int meterLocationCurrent) { - this.meterLocationCurrent = meterLocationCurrent; - } - - public double getPowerApparentSPhase1() { - return powerApparentSPhase1; - } - - public void setPowerApparentSPhase1(double powerApparentSPhase1) { - this.powerApparentSPhase1 = powerApparentSPhase1; - } - - public double getPowerApparentSPhase2() { - return powerApparentSPhase2; - } - - public void setPowerApparentSPhase2(double powerApparentSPhase2) { - this.powerApparentSPhase2 = powerApparentSPhase2; - } - - public double getPowerApparentSPhase3() { - return powerApparentSPhase3; - } - - public void setPowerApparentSPhase3(double powerApparentSPhase3) { - this.powerApparentSPhase3 = powerApparentSPhase3; - } - - public double getPowerApparentSSum() { - return powerApparentSSum; - } - - public void setPowerApparentSSum(double powerApparentSSum) { - this.powerApparentSSum = powerApparentSSum; - } - - public double getPowerFactorPhase1() { - return powerFactorPhase1; - } - - public void setPowerFactorPhase1(double powerFactorPhase1) { - this.powerFactorPhase1 = powerFactorPhase1; - } - - public double getPowerFactorPhase2() { - return powerFactorPhase2; - } - - public void setPowerFactorPhase2(double powerFactorPhase2) { - this.powerFactorPhase2 = powerFactorPhase2; - } - - public double getPowerFactorPhase3() { - return powerFactorPhase3; - } - - public void setPowerFactorPhase3(double powerFactorPhase3) { - this.powerFactorPhase3 = powerFactorPhase3; - } - - public double getPowerFactorSum() { - return powerFactorSum; - } - - public void setPowerFactorSum(double powerFactorSum) { - this.powerFactorSum = powerFactorSum; - } - - public double getPowerReactiveQPhase1() { - return powerReactiveQPhase1; - } - - public void setPowerReactiveQPhase1(double powerReactiveQPhase1) { - this.powerReactiveQPhase1 = powerReactiveQPhase1; - } - - public double getPowerReactiveQPhase2() { - return powerReactiveQPhase2; - } - - public void setPowerReactiveQPhase2(double powerReactiveQPhase2) { - this.powerReactiveQPhase2 = powerReactiveQPhase2; - } - - public double getPowerReactiveQPhase3() { - return powerReactiveQPhase3; - } - - public void setPowerReactiveQPhase3(double powerReactiveQPhase3) { - this.powerReactiveQPhase3 = powerReactiveQPhase3; - } - - public double getPowerReactiveQSum() { - return powerReactiveQSum; - } - - public void setPowerReactiveQSum(double powerReactiveQSum) { - this.powerReactiveQSum = powerReactiveQSum; - } - - public double getPowerRealPPhase1() { - return powerRealPPhase1; - } - - public void setPowerRealPPhase1(double powerRealPPhase1) { - this.powerRealPPhase1 = powerRealPPhase1; - } - - public double getPowerRealPPhase2() { - return powerRealPPhase2; - } - - public void setPowerRealPPhase2(double powerRealPPhase2) { - this.powerRealPPhase2 = powerRealPPhase2; - } - - public double getPowerRealPPhase3() { - return powerRealPPhase3; - } - - public void setPowerRealPPhase3(double powerRealPPhase3) { - this.powerRealPPhase3 = powerRealPPhase3; - } - - public double getPowerRealPSum() { - return powerRealPSum; - } - - public void setPowerRealPSum(double powerRealPSum) { - this.powerRealPSum = powerRealPSum; - } - - public int getTimeStamp() { - return timeStamp; - } - - public void setTimeStamp(int timeStamp) { - this.timeStamp = timeStamp; - } - - public int getVisible() { - return visible; - } - - public void setVisible(int visible) { - this.visible = visible; - } - - public double getVoltageACPhaseToPhase12() { - return voltageACPhaseToPhase12; - } - - public void setVoltageACPhaseToPhase12(double voltageACPhaseToPhase12) { - this.voltageACPhaseToPhase12 = voltageACPhaseToPhase12; - } - - public double getVoltageACPhaseToPhase23() { - return voltageACPhaseToPhase23; - } - - public void setVoltageACPhaseToPhase23(double voltageACPhaseToPhase23) { - this.voltageACPhaseToPhase23 = voltageACPhaseToPhase23; - } - - public double getVoltageACPhaseToPhase31() { - return voltageACPhaseToPhase31; - } - - public void setVoltageACPhaseToPhase31(double voltageACPhaseToPhase31) { - this.voltageACPhaseToPhase31 = voltageACPhaseToPhase31; - } - - public double getVoltageACPhase1() { - return voltageACPhase1; - } - - public void setVoltageACPhase1(double voltageACPhase1) { - this.voltageACPhase1 = voltageACPhase1; - } - - public double getVoltageACPhase2() { - return voltageACPhase2; - } - - public void setVoltageACPhase2(double voltageACPhase2) { - this.voltageACPhase2 = voltageACPhase2; - } - - public double getVoltageACPhase3() { - return voltageACPhase3; - } - - public void setVoltageACPhase3(double voltageACPhase3) { - this.voltageACPhase3 = voltageACPhase3; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeDetailsDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeDetailsDTO.java deleted file mode 100644 index 0322b36fe2..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeDetailsDTO.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link MeterRealtimeDetailsDTO} is responsible for storing - * the "body" node of the JSON response - * - * @author Jimmy Tanagra - Initial contribution - */ -public class MeterRealtimeDetailsDTO { - @SerializedName("Manufacturer") - private String manufacturer; - @SerializedName("Model") - private String model; - @SerializedName("Serial") - private String serial; - - public String getManufacturer() { - return manufacturer; - } - - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } - - public String getModel() { - return model; - } - - public void setModel(String model) { - this.model = model; - } - - public String getSerial() { - return serial; - } - - public void setSerial(String serial) { - this.serial = serial; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeResponseDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeResponseDTO.java deleted file mode 100644 index 88265d7b07..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/MeterRealtimeResponseDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link MeterRealtimeResponseDTO} is responsible for storing - * the response from the powerflowrealtime api - * - * @author Jimmy Tanagra - Initial contribution - */ -public class MeterRealtimeResponseDTO extends BaseFroniusResponse { - @SerializedName("Body") - private MeterRealtimeBodyDTO body; - - public MeterRealtimeBodyDTO getBody() { - if (body == null) { - body = new MeterRealtimeBodyDTO(); - } - return body; - } - - public void setBody(MeterRealtimeBodyDTO body) { - this.body = body; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java deleted file mode 100644 index 1fa308e324..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link OhmpilotRealtimeBodyDTO} is responsible for storing - * the "body" node of the JSON response - * - * @author Hannes Spenger - Initial contribution - */ -public class OhmpilotRealtimeBodyDTO { - @SerializedName("Data") - private OhmpilotRealtimeBodyDataDTO data; - - public OhmpilotRealtimeBodyDataDTO getData() { - if (data == null) { - data = new OhmpilotRealtimeBodyDataDTO(); - } - return data; - } - - public void setData(OhmpilotRealtimeBodyDataDTO data) { - this.data = data; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java deleted file mode 100644 index 27ed84caed..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeBodyDataDTO.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link OhmpilotRealtimeBodyDataDTO} is responsible for storing - * the "data" node of the JSON response - * - * @author Hannes Spenger - Initial contribution - */ -public class OhmpilotRealtimeBodyDataDTO { - @SerializedName("Details") - private OhmpilotRealtimeDetailsDTO details; - @SerializedName("EnergyReal_WAC_Sum_Consumed") - private double energyRealWACSumConsumed; - @SerializedName("PowerReal_PAC_Sum") - private double powerPACSum; - @SerializedName("Temperature_Channel_1") - private double temperatureChannel1; - @SerializedName("CodeOfError") - private int errorCode; - @SerializedName("CodeOfState") - private int stateCode; - - public OhmpilotRealtimeDetailsDTO getDetails() { - if (details == null) { - details = new OhmpilotRealtimeDetailsDTO(); - } - return details; - } - - public void setDetails(OhmpilotRealtimeDetailsDTO details) { - this.details = details; - } - - public double getEnergyRealWACSumConsumed() { - return energyRealWACSumConsumed; - } - - public void setEnergyRealWACSumConsumed(double energyRealWACSumConsumed) { - this.energyRealWACSumConsumed = energyRealWACSumConsumed; - } - - public double getPowerPACSum() { - return powerPACSum; - } - - public void setPowerPACSum(double powerPACSum) { - this.powerPACSum = powerPACSum; - } - - public double getTemperatureChannel1() { - return temperatureChannel1; - } - - public void setTemperatureChannel1(double temperatureChannel1) { - this.temperatureChannel1 = temperatureChannel1; - } - - public int getErrorCode() { - return errorCode; - } - - public void setErrorCode(int errorCode) { - this.errorCode = errorCode; - } - - public int getStateCode() { - return stateCode; - } - - public void setStateCode(int stateCode) { - this.stateCode = stateCode; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java deleted file mode 100644 index 32dda4cee6..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeDetailsDTO.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link OhmpilotRealtimeDetailsDTO} is responsible for storing - * the "body" node of the JSON response - * - * @author Hannes Spenger - Initial contribution - */ -public class OhmpilotRealtimeDetailsDTO { - @SerializedName("Hardware") - private String hardware; - @SerializedName("Manufacturer") - private String manufacturer; - @SerializedName("Model") - private String model; - @SerializedName("Serial") - private String serial; - @SerializedName("Software") - private String software; - - public String getHardware() { - return hardware; - } - - public void setHardware(String hardware) { - this.hardware = hardware; - } - - public String getManufacturer() { - return manufacturer; - } - - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; - } - - public String getModel() { - return model; - } - - public void setModel(String model) { - this.model = model; - } - - public String getSerial() { - return serial; - } - - public void setSerial(String serial) { - this.serial = serial; - } - - public String getSoftware() { - return software; - } - - public void setSoftware(String software) { - this.software = software; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java deleted file mode 100644 index 9d76a44191..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/OhmpilotRealtimeResponseDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link OhmpilotRealtimeResponseDTO} is responsible for storing - * the response from the GetOhmPilotRealtimeData api - * - * @author Hannes Spenger - Initial contribution - */ -public class OhmpilotRealtimeResponseDTO extends BaseFroniusResponse { - @SerializedName("Body") - private OhmpilotRealtimeBodyDTO body; - - public OhmpilotRealtimeBodyDTO getBody() { - if (body == null) { - body = new OhmpilotRealtimeBodyDTO(); - } - return body; - } - - public void setBody(OhmpilotRealtimeBodyDTO body) { - this.body = body; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBody.java deleted file mode 100644 index 0efe842b2f..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBody.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link PowerFlowRealtimeBody} is responsible for storing - * the "body" node of the JSON response - * - * @author Thomas Rokohl - Initial contribution - */ -public class PowerFlowRealtimeBody { - @SerializedName("Data") - private PowerFlowRealtimeBodyData data; - - public PowerFlowRealtimeBodyData getData() { - if (data == null) { - data = new PowerFlowRealtimeBodyData(); - } - return data; - } - - public void setData(PowerFlowRealtimeBodyData data) { - this.data = data; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBodyData.java deleted file mode 100644 index 76617c22ae..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeBodyData.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import java.util.HashMap; -import java.util.Map; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link PowerFlowRealtimeBodyData} is responsible for storing - * the "data" node of the JSON response - * - * @author Thomas Rokohl - Initial contribution - */ -public class PowerFlowRealtimeBodyData { - - @SerializedName("Site") - private PowerFlowRealtimeSite site; - - @SerializedName("Inverters") - private Map inverters; - - public Map getInverters() { - if (inverters == null) { - inverters = new HashMap<>(); - } - return inverters; - } - - public void setInverters(Map inverters) { - this.inverters = inverters; - } - - public PowerFlowRealtimeSite getSite() { - if (site == null) { - site = new PowerFlowRealtimeSite(); - } - return site; - } - - public void setSite(PowerFlowRealtimeSite site) { - this.site = site; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeInverter.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeInverter.java deleted file mode 100644 index 3da812fa89..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeInverter.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link PowerFlowRealtimeInverter} is responsible for storing - * the "inverter" node of the JSON response - * - * @author Thomas Rokohl - Initial contribution - * @author Thomas Kordelle - Added inverter power, battery state of charge and PV solar yield - */ -public class PowerFlowRealtimeInverter { - - @SerializedName("DT") - private double dt; - @SerializedName("P") - private double p; - @SerializedName("E_Day") - private double eDay; - @SerializedName("E_Year") - private double eYear; - @SerializedName("E_Total") - private double eTotal; - @SerializedName("Battery_Mode") - private String batteryMode; - @SerializedName("SOC") - private double soc; - - public double getDt() { - return dt; - } - - public void setDt(double dt) { - this.dt = dt; - } - - public double getP() { - return p; - } - - public void setP(double p) { - this.p = p; - } - - public double geteDay() { - return eDay; - } - - public void seteDay(double eDay) { - this.eDay = eDay; - } - - public double geteYear() { - return eYear; - } - - public void seteYear(double eYear) { - this.eYear = eYear; - } - - public double geteTotal() { - return eTotal; - } - - public void seteTotal(double eTotal) { - this.eTotal = eTotal; - } - - public String getBatteryMode() { - return batteryMode; - } - - public void setBatteryMode(final String batteryMode) { - this.batteryMode = batteryMode; - } - - public double getSoc() { - return soc; - } - - public void setSoc(double soc) { - this.soc = soc; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeResponse.java deleted file mode 100644 index b13af18626..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link PowerFlowRealtimeResponse} is responsible for storing - * the response from the powerflowrealtime api - * - * @author Thomas Rokohl - Initial contribution - */ -public class PowerFlowRealtimeResponse extends BaseFroniusResponse { - @SerializedName("Body") - private PowerFlowRealtimeBody body; - - public PowerFlowRealtimeBody getBody() { - if (body == null) { - body = new PowerFlowRealtimeBody(); - } - return body; - } - - public void setBody(PowerFlowRealtimeBody body) { - this.body = body; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeSite.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeSite.java deleted file mode 100644 index 7f49d57452..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/PowerFlowRealtimeSite.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link PowerFlowRealtimeSite} is responsible for storing - * the "site" node - * - * @author Thomas Rokohl - Initial contribution - */ -public class PowerFlowRealtimeSite { - - @SerializedName("Mode") - private String mode; - @SerializedName("P_Grid") - private double pgrid; - @SerializedName("P_Load") - private double pload; - @SerializedName("P_Akku") - private double pakku; - @SerializedName("P_PV") - private double ppv; - @SerializedName("rel_SelfConsumption") - private double relSelfConsumption; - @SerializedName("rel_Autonomy") - private double relAutonomy; - @SerializedName("E_Day") - private double eDay; - @SerializedName("E_Year") - private double eYear; - @SerializedName("E_Total") - private double eTotal; - @SerializedName("Meter_Location") - private String meterLocation; - - public String getMode() { - if (mode == null) { - mode = ""; - } - return mode; - } - - public void setMode(String mode) { - this.mode = mode; - } - - public double getPgrid() { - return pgrid; - } - - public void setPgrid(double pgrid) { - this.pgrid = pgrid; - } - - public double getPload() { - return pload; - } - - public void setPload(double pload) { - this.pload = pload; - } - - public double getPakku() { - return pakku; - } - - public void setPakku(double pakku) { - this.pakku = pakku; - } - - public double getPpv() { - return ppv; - } - - public void setPpv(double ppv) { - this.ppv = ppv; - } - - public double getRelSelfConsumption() { - return relSelfConsumption; - } - - public void setRelSelfConsumption(double relSelfConsumption) { - this.relSelfConsumption = relSelfConsumption; - } - - public double getRelAutonomy() { - return relAutonomy; - } - - public void setRelAutonomy(double relAutonomy) { - this.relAutonomy = relAutonomy; - } - - public double geteDay() { - return eDay; - } - - public void seteDay(double eDay) { - this.eDay = eDay; - } - - public double geteYear() { - return eYear; - } - - public void seteYear(double eYear) { - this.eYear = eYear; - } - - public double geteTotal() { - return eTotal; - } - - public void seteTotal(double eTotal) { - this.eTotal = eTotal; - } - - public String getMeterLocation() { - return meterLocation; - } - - public void setMeterLocation(String meterLocation) { - this.meterLocation = meterLocation; - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/ValueUnit.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/ValueUnit.java deleted file mode 100644 index e0d6593491..0000000000 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/ValueUnit.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.fronius.internal.api; - -import javax.measure.Unit; - -import org.openhab.core.library.types.QuantityType; -import org.openhab.core.types.util.UnitUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.annotations.SerializedName; - -/** - * The {@link InverterRealtimeResponse} is responsible for storing - * a value - * - * @author Thomas Rokohl - Initial contribution - * @author Jimmy Tanagra - Add conversion to QuantityType - */ -public class ValueUnit { - - @SerializedName("Value") - private double value; - @SerializedName("Unit") - private String unit = ""; - - public double getValue() { - return value; - } - - public void setValue(double value) { - this.value = value; - } - - public String getUnit() { - return this.unit == null ? "" : this.unit; - } - - public void setUnit(String unit) { - this.unit = unit; - } - - public QuantityType asQuantityType() { - Unit unit = UnitUtils.parseUnit(getUnit()); - if (unit == null) { - final Logger logger = LoggerFactory.getLogger(ValueUnit.class); - logger.debug("The unit for ValueUnit ({})/({}) cannot be parsed", value, this.unit); - unit = QuantityType.ONE.getUnit(); - } - return new QuantityType<>(value, unit); - } -} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/BaseFroniusResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/BaseFroniusResponse.java new file mode 100644 index 0000000000..7fae834d6b --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/BaseFroniusResponse.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * Base class for a response-object from the Fronius Solar API (v1). + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class BaseFroniusResponse { + @SerializedName("Head") + private @Nullable Head head; + + public @Nullable Head getHead() { + return head; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/Head.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/Head.java new file mode 100644 index 0000000000..e621d2826e --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/Head.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link Head} is responsible for storing the "Head" node of the JSON response from the + * {@link BaseFroniusResponse}. + * + * The contents of the response object will vary depending on the preceding request but it always contains a common + * response header and a request body. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class Head { + @SerializedName("RequestArguments") + private @Nullable HeadRequestArguments requestArguments; + @SerializedName("Status") + private @Nullable HeadStatus status; + @SerializedName("Timestamp") + private @Nullable String timestamp; + + public @Nullable HeadRequestArguments getRequestArguments() { + return requestArguments; + } + + public @Nullable HeadStatus getStatus() { + return status; + } + + public @Nullable String getTimestamp() { + return timestamp; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadRequestArguments.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadRequestArguments.java new file mode 100644 index 0000000000..a162aac933 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadRequestArguments.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link HeadRequestArguments} is responsible for storing the "RequestArguments" node from the {@link Head}. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class HeadRequestArguments { + @SerializedName("DataCollection") + private @Nullable String dataCollection; + @SerializedName("DeviceClass") + private @Nullable String deviceClass; + @SerializedName("DeviceId") + private @Nullable String deviceId; + @SerializedName("Scope") + private @Nullable String scope; + + public @Nullable String getDataCollection() { + return dataCollection; + } + + public @Nullable String getDeviceClass() { + return deviceClass; + } + + public @Nullable String getDeviceId() { + return deviceId; + } + + public @Nullable String getScope() { + return scope; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadStatus.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadStatus.java new file mode 100644 index 0000000000..aaf4f64ce4 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/HeadStatus.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link HeadStatus} is responsible for storing the "Status" node from the {@link Head}. + * + * @author Thomas Rokohl - Initial contribution + */ +public class HeadStatus { + @SerializedName("Code") + private int code; + @SerializedName("Reason") + private String reason; + @SerializedName("UserMessage") + private String userMessage; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getReason() { + if (reason == null) { + reason = ""; + } + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public String getUserMessage() { + if (userMessage == null) { + userMessage = ""; + } + return userMessage; + } + + public void setUserMessage(String userMessage) { + this.userMessage = userMessage; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ValueUnit.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ValueUnit.java new file mode 100644 index 0000000000..82ba2e67e1 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ValueUnit.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto; + +import javax.measure.Unit; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.library.types.QuantityType; +import org.openhab.core.types.util.UnitUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link ValueUnit} is responsible for storing a value. + * + * @author Thomas Rokohl - Initial contribution + * @author Jimmy Tanagra - Add conversion to QuantityType + */ +@NonNullByDefault +public class ValueUnit { + @SerializedName("Value") + private double value; + @SerializedName("Unit") + private @Nullable String unit = ""; + + public double getValue() { + return value; + } + + public @Nullable String getUnit() { + return unit; + } + + public QuantityType asQuantityType() { + Unit unit = UnitUtils.parseUnit(getUnit()); + if (unit == null) { + final Logger logger = LoggerFactory.getLogger(ValueUnit.class); + logger.debug("The unit for ValueUnit ({})/({}) cannot be parsed", value, this.unit); + unit = QuantityType.ONE.getUnit(); + } + return new QuantityType<>(value, unit); + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterDeviceStatus.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterDeviceStatus.java new file mode 100644 index 0000000000..88e9212071 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterDeviceStatus.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.inverter; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link InverterDeviceStatus} is responsible for storing + * the "DeviceStatus" node of the {@link InverterRealtimeBodyData}. + * + * @author Thomas Rokohl - Initial contribution + */ +public class InverterDeviceStatus { + @SerializedName("StatusCode") + private int statusCode; + @SerializedName("MgmtTimerRemainingTime") + private int mgmtTimerRemainingTime; + @SerializedName("ErrorCode") + private int errorCode; + @SerializedName("LEDColor") + private int ledColor; + @SerializedName("LEDState") + private int ledState; + @SerializedName("StateToReset") + private boolean stateToReset; + + public int getStatusCode() { + return statusCode; + } + + public int getMgmtTimerRemainingTime() { + return mgmtTimerRemainingTime; + } + + public int getErrorCode() { + return errorCode; + } + + public int getLedColor() { + return ledColor; + } + + public int getLedState() { + return ledState; + } + + public boolean isStateToReset() { + return stateToReset; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBody.java new file mode 100644 index 0000000000..7395f75b52 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBody.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.inverter; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link InverterRealtimeBody} is responsible for storing + * the "Body" node of the {@link InverterRealtimeResponse}. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class InverterRealtimeBody { + @SerializedName("Data") + private @Nullable InverterRealtimeBodyData data; + + public @Nullable InverterRealtimeBodyData getData() { + return data; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBodyData.java new file mode 100644 index 0000000000..7cb493e53a --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeBodyData.java @@ -0,0 +1,111 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.inverter; + +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.fronius.internal.api.dto.ValueUnit; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link InverterRealtimeBodyData} is responsible for storing + * the "Data" node of the {@link InverterRealtimeBody}. + * + * @author Thomas Rokohl - Initial contribution + */ +public class InverterRealtimeBodyData { + @SerializedName("DAY_ENERGY") + private ValueUnit dayEnergy; + @SerializedName("FAC") + private ValueUnit fac; + @SerializedName("IAC") + private ValueUnit iac; + @SerializedName("IDC") + private ValueUnit idc; + @SerializedName("IDC_2") + private ValueUnit idc2; + @SerializedName("IDC_3") + private ValueUnit idc3; + @SerializedName("PAC") + private ValueUnit pac; + @SerializedName("TOTAL_ENERGY") + private ValueUnit totalEnergy; + @SerializedName("UAC") + private ValueUnit uac; + @SerializedName("UDC") + private ValueUnit udc; + @SerializedName("UDC_2") + private ValueUnit udc2; + @SerializedName("UDC_3") + private ValueUnit udc3; + @SerializedName("YEAR_ENERGY") + private ValueUnit yearEnergy; + @SerializedName("DeviceStatus") + private InverterDeviceStatus deviceStatus; + + public ValueUnit getDayEnergy() { + return dayEnergy; + } + + public ValueUnit getPac() { + return pac; + } + + public ValueUnit getTotalEnergy() { + return totalEnergy; + } + + public ValueUnit getYearEnergy() { + return yearEnergy; + } + + public @Nullable InverterDeviceStatus getDeviceStatus() { + return deviceStatus; + } + + public ValueUnit getFac() { + return fac; + } + + public ValueUnit getIac() { + return iac; + } + + public ValueUnit getIdc() { + return idc; + } + + public ValueUnit getIdc2() { + return idc2; + } + + public ValueUnit getIdc3() { + return idc3; + } + + public ValueUnit getUac() { + return uac; + } + + public ValueUnit getUdc() { + return udc; + } + + public ValueUnit getUdc2() { + return udc2; + } + + public ValueUnit getUdc3() { + return udc3; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeResponse.java new file mode 100644 index 0000000000..8e7e74bfa7 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/InverterRealtimeResponse.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.inverter; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.fronius.internal.api.dto.BaseFroniusResponse; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link InverterRealtimeResponse} is responsible for storing + * the response from the GetInverterRealtimeData response. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class InverterRealtimeResponse extends BaseFroniusResponse { + @SerializedName("Body") + private @Nullable InverterRealtimeBody body; + + public @Nullable InverterRealtimeBody getBody() { + return body; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBody.java new file mode 100644 index 0000000000..06992e9e5c --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBody.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.meter; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link MeterRealtimeBody} is responsible for storing + * the "Body" node of the {@link MeterRealtimeResponse}. + * + * @author Jimmy Tanagra - Initial contribution + */ +@NonNullByDefault +public class MeterRealtimeBody { + @SerializedName("Data") + private @Nullable MeterRealtimeBodyData data; + + public @Nullable MeterRealtimeBodyData getData() { + return data; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBodyData.java new file mode 100644 index 0000000000..c87f7107b6 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeBodyData.java @@ -0,0 +1,255 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.meter; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link MeterRealtimeBodyData} is responsible for storing + * the "Data" node of the {@link MeterRealtimeBody}. + * + * The main SerializedName values use Smart Meter 63A names + * The first SerializedName alternate names use Smart Meter 65A names + * + * @author Jimmy Tanagra - Initial contribution + */ +public class MeterRealtimeBodyData { + @SerializedName(value = "Current_AC_Phase_1", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_01_F32" }) + private double currentACPhase1; + @SerializedName(value = "Current_AC_Phase_2", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_02_F32" }) + private double currentACPhase2; + @SerializedName(value = "Current_AC_Phase_3", alternate = { "ACBRIDGE_CURRENT_ACTIVE_MEAN_03_F32" }) + private double currentACPhase3; + @SerializedName("Details") + private MeterRealtimeDetails details; + @SerializedName(value = "Enable", alternate = { "COMPONENTS_MODE_ENABLE_U16" }) + private int enable; + @SerializedName(value = "EnergyReactive_VArAC_Sum_Consumed", alternate = { + "SMARTMETER_ENERGYREACTIVE_CONSUMED_SUM_F64" }) + private double energyReactiveVArACSumConsumed; + @SerializedName(value = "EnergyReactive_VArAC_Sum_Produced", alternate = { + "SMARTMETER_ENERGYREACTIVE_PRODUCED_SUM_F64" }) + private double energyReactiveVArACSumProduced; + @SerializedName(value = "EnergyReal_WAC_Minus_Absolute", alternate = { + "SMARTMETER_ENERGYACTIVE_ABSOLUT_MINUS_F64" }) + private double energyRealWACMinusAbsolute; + @SerializedName(value = "EnergyReal_WAC_Plus_Absolute", alternate = { "SMARTMETER_ENERGYACTIVE_ABSOLUT_PLUS_F64" }) + private double energyRealWACPlusAbsolute; + @SerializedName(value = "EnergyReal_WAC_Sum_Consumed", alternate = { "SMARTMETER_ENERGYACTIVE_CONSUMED_SUM_F64" }) + private double energyRealWACSumConsumed; + @SerializedName(value = "EnergyReal_WAC_Sum_Produced", alternate = { "SMARTMETER_ENERGYACTIVE_PRODUCED_SUM_F64" }) + private double energyRealWACSumProduced; + @SerializedName(value = "Frequency_Phase_Average", alternate = { "GRID_FREQUENCY_MEAN_F32" }) + private double frequencyPhaseAverage; + @SerializedName(value = "Meter_Location_Current", alternate = { "SMARTMETER_VALUE_LOCATION_U16" }) + private int meterLocationCurrent; + @SerializedName(value = "PowerApparent_S_Phase_1", alternate = { "SMARTMETER_POWERAPPARENT_01_F64" }) + private double powerApparentSPhase1; + @SerializedName(value = "PowerApparent_S_Phase_2", alternate = { "SMARTMETER_POWERAPPARENT_02_F64" }) + private double powerApparentSPhase2; + @SerializedName(value = "PowerApparent_S_Phase_3", alternate = { "SMARTMETER_POWERAPPARENT_03_F64" }) + private double powerApparentSPhase3; + @SerializedName(value = "PowerApparent_S_Sum", alternate = { "SMARTMETER_POWERAPPARENT_MEAN_SUM_F64" }) + private double powerApparentSSum; + @SerializedName(value = "PowerFactor_Phase_1", alternate = { "SMARTMETER_FACTOR_POWER_01_F64" }) + private double powerFactorPhase1; + @SerializedName(value = "PowerFactor_Phase_2", alternate = { "SMARTMETER_FACTOR_POWER_02_F64" }) + private double powerFactorPhase2; + @SerializedName(value = "PowerFactor_Phase_3", alternate = { "SMARTMETER_FACTOR_POWER_03_F64" }) + private double powerFactorPhase3; + @SerializedName(value = "PowerFactor_Sum", alternate = { "SMARTMETER_FACTOR_POWER_SUM_F64" }) + private double powerFactorSum; + @SerializedName(value = "PowerReactive_Q_Phase_1", alternate = { "SMARTMETER_POWERREACTIVE_01_F64" }) + private double powerReactiveQPhase1; + @SerializedName(value = "PowerReactive_Q_Phase_2", alternate = { "SMARTMETER_POWERREACTIVE_02_F64" }) + private double powerReactiveQPhase2; + @SerializedName(value = "PowerReactive_Q_Phase_3", alternate = { "SMARTMETER_POWERREACTIVE_03_F64" }) + private double powerReactiveQPhase3; + @SerializedName(value = "PowerReactive_Q_Sum", alternate = { "SMARTMETER_POWERREACTIVE_MEAN_SUM_F64" }) + private double powerReactiveQSum; + @SerializedName(value = "PowerReal_P_Phase_1", alternate = { "SMARTMETER_POWERACTIVE_01_F64" }) + private double powerRealPPhase1; + @SerializedName(value = "PowerReal_P_Phase_2", alternate = { "SMARTMETER_POWERACTIVE_02_F64" }) + private double powerRealPPhase2; + @SerializedName(value = "PowerReal_P_Phase_3", alternate = { "SMARTMETER_POWERACTIVE_03_F64" }) + private double powerRealPPhase3; + @SerializedName(value = "PowerReal_P_Sum", alternate = { "SMARTMETER_POWERACTIVE_MEAN_SUM_F64" }) + private double powerRealPSum; + @SerializedName("TimeStamp") + private int timeStamp; + @SerializedName(value = "Visible", alternate = { "COMPONENTS_MODE_VISIBLE_U16" }) + private int visible; + @SerializedName(value = "Voltage_AC_PhaseToPhase_12", alternate = { "ACBRIDGE_VOLTAGE_MEAN_12_F32" }) + private double voltageACPhaseToPhase12; + @SerializedName(value = "Voltage_AC_PhaseToPhase_23", alternate = { "ACBRIDGE_VOLTAGE_MEAN_23_F32" }) + private double voltageACPhaseToPhase23; + @SerializedName(value = "Voltage_AC_PhaseToPhase_31", alternate = { "ACBRIDGE_VOLTAGE_MEAN_31_F32" }) + private double voltageACPhaseToPhase31; + @SerializedName(value = "Voltage_AC_Phase_1", alternate = { "SMARTMETER_VOLTAGE_01_F64" }) + private double voltageACPhase1; + @SerializedName(value = "Voltage_AC_Phase_2", alternate = { "SMARTMETER_VOLTAGE_02_F64" }) + private double voltageACPhase2; + @SerializedName(value = "Voltage_AC_Phase_3", alternate = { "SMARTMETER_VOLTAGE_03_F64" }) + private double voltageACPhase3; + + public double getCurrentACPhase1() { + return currentACPhase1; + } + + public double getCurrentACPhase2() { + return currentACPhase2; + } + + public double getCurrentACPhase3() { + return currentACPhase3; + } + + public MeterRealtimeDetails getDetails() { + if (details == null) { + details = new MeterRealtimeDetails(); + } + return details; + } + + public int getEnable() { + return enable; + } + + public double getEnergyReactiveVArACSumConsumed() { + return energyReactiveVArACSumConsumed; + } + + public double getEnergyReactiveVArACSumProduced() { + return energyReactiveVArACSumProduced; + } + + public double getEnergyRealWACMinusAbsolute() { + return energyRealWACMinusAbsolute; + } + + public double getEnergyRealWACPlusAbsolute() { + return energyRealWACPlusAbsolute; + } + + public double getEnergyRealWACSumConsumed() { + return energyRealWACSumConsumed; + } + + public double getEnergyRealWACSumProduced() { + return energyRealWACSumProduced; + } + + public double getFrequencyPhaseAverage() { + return frequencyPhaseAverage; + } + + public int getMeterLocationCurrent() { + return meterLocationCurrent; + } + + public double getPowerApparentSPhase1() { + return powerApparentSPhase1; + } + + public double getPowerApparentSPhase2() { + return powerApparentSPhase2; + } + + public double getPowerApparentSPhase3() { + return powerApparentSPhase3; + } + + public double getPowerApparentSSum() { + return powerApparentSSum; + } + + public double getPowerFactorPhase1() { + return powerFactorPhase1; + } + + public double getPowerFactorPhase2() { + return powerFactorPhase2; + } + + public double getPowerFactorPhase3() { + return powerFactorPhase3; + } + + public double getPowerFactorSum() { + return powerFactorSum; + } + + public double getPowerReactiveQPhase1() { + return powerReactiveQPhase1; + } + + public double getPowerReactiveQPhase2() { + return powerReactiveQPhase2; + } + + public double getPowerReactiveQPhase3() { + return powerReactiveQPhase3; + } + + public double getPowerReactiveQSum() { + return powerReactiveQSum; + } + + public double getPowerRealPPhase1() { + return powerRealPPhase1; + } + + public double getPowerRealPPhase2() { + return powerRealPPhase2; + } + + public double getPowerRealPPhase3() { + return powerRealPPhase3; + } + + public double getPowerRealPSum() { + return powerRealPSum; + } + + public int getTimeStamp() { + return timeStamp; + } + + public int getVisible() { + return visible; + } + + public double getVoltageACPhaseToPhase12() { + return voltageACPhaseToPhase12; + } + + public double getVoltageACPhaseToPhase23() { + return voltageACPhaseToPhase23; + } + + public double getVoltageACPhaseToPhase31() { + return voltageACPhaseToPhase31; + } + + public double getVoltageACPhase1() { + return voltageACPhase1; + } + + public double getVoltageACPhase2() { + return voltageACPhase2; + } + + public double getVoltageACPhase3() { + return voltageACPhase3; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeDetails.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeDetails.java new file mode 100644 index 0000000000..13e5b4030b --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeDetails.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.meter; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link MeterRealtimeDetails} is responsible for storing + * the "Details" node of the {@link MeterRealtimeBodyData}. + * + * @author Jimmy Tanagra - Initial contribution + */ +public class MeterRealtimeDetails { + @SerializedName("Manufacturer") + private String manufacturer; + @SerializedName("Model") + private String model; + @SerializedName("Serial") + private String serial; + + public String getManufacturer() { + return manufacturer; + } + + public String getModel() { + return model; + } + + public String getSerial() { + return serial; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeResponse.java new file mode 100644 index 0000000000..54daee74d5 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/meter/MeterRealtimeResponse.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.meter; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.fronius.internal.api.dto.BaseFroniusResponse; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link MeterRealtimeResponse} is responsible for storing + * the response from the GetMeterRealtimeData response. + * + * @author Jimmy Tanagra - Initial contribution + */ +@NonNullByDefault +public class MeterRealtimeResponse extends BaseFroniusResponse { + @SerializedName("Body") + private @Nullable MeterRealtimeBody body; + + public @Nullable MeterRealtimeBody getBody() { + return body; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBody.java new file mode 100644 index 0000000000..216b5e194c --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBody.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.ohmpilot; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeBody} is responsible for storing + * the "Body" node of the {@link OhmpilotRealtimeResponse}. + * + * @author Hannes Spenger - Initial contribution + */ +@NonNullByDefault +public class OhmpilotRealtimeBody { + @SerializedName("Data") + private @Nullable OhmpilotRealtimeBodyData data; + + public @Nullable OhmpilotRealtimeBodyData getData() { + return data; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBodyData.java new file mode 100644 index 0000000000..20adcabdd0 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeBodyData.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.ohmpilot; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeBodyData} is responsible for storing + * the "Data" node of the {@link OhmpilotRealtimeBody}. + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeBodyData { + @SerializedName("Details") + private OhmpilotRealtimeDetails details; + @SerializedName("EnergyReal_WAC_Sum_Consumed") + private double energyRealWACSumConsumed; + @SerializedName("PowerReal_PAC_Sum") + private double powerPACSum; + @SerializedName("Temperature_Channel_1") + private double temperatureChannel1; + @SerializedName("CodeOfError") + private int errorCode; + @SerializedName("CodeOfState") + private int stateCode; + + public OhmpilotRealtimeDetails getDetails() { + if (details == null) { + details = new OhmpilotRealtimeDetails(); + } + return details; + } + + public double getEnergyRealWACSumConsumed() { + return energyRealWACSumConsumed; + } + + public double getPowerPACSum() { + return powerPACSum; + } + + public double getTemperatureChannel1() { + return temperatureChannel1; + } + + public int getErrorCode() { + return errorCode; + } + + public int getStateCode() { + return stateCode; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeDetails.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeDetails.java new file mode 100644 index 0000000000..70375c92be --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeDetails.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.ohmpilot; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeDetails} is responsible for storing + * the "Details" node of the {@link OhmpilotRealtimeBodyData}. + * + * @author Hannes Spenger - Initial contribution + */ +public class OhmpilotRealtimeDetails { + @SerializedName("Hardware") + private String hardware; + @SerializedName("Manufacturer") + private String manufacturer; + @SerializedName("Model") + private String model; + @SerializedName("Serial") + private String serial; + @SerializedName("Software") + private String software; + + public String getHardware() { + return hardware; + } + + public void setHardware(String hardware) { + this.hardware = hardware; + } + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getSerial() { + return serial; + } + + public void setSerial(String serial) { + this.serial = serial; + } + + public String getSoftware() { + return software; + } + + public void setSoftware(String software) { + this.software = software; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeResponse.java new file mode 100644 index 0000000000..e9b67595b3 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/ohmpilot/OhmpilotRealtimeResponse.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.ohmpilot; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.fronius.internal.api.dto.BaseFroniusResponse; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link OhmpilotRealtimeResponse} is responsible for storing + * the response from the GetOhmPilotRealtimeData response. + * + * @author Hannes Spenger - Initial contribution + */ +@NonNullByDefault +public class OhmpilotRealtimeResponse extends BaseFroniusResponse { + @SerializedName("Body") + private @Nullable OhmpilotRealtimeBody body; + + public @Nullable OhmpilotRealtimeBody getBody() { + return body; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBody.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBody.java new file mode 100644 index 0000000000..82e4e8636f --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBody.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.powerflow; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link PowerFlowRealtimeBody} is responsible for storing + * the "Body" node of the {@link PowerFlowRealtimeResponse}. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class PowerFlowRealtimeBody { + @SerializedName("Data") + private @Nullable PowerFlowRealtimeBodyData data; + + public @Nullable PowerFlowRealtimeBodyData getData() { + return data; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBodyData.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBodyData.java new file mode 100644 index 0000000000..19824d2195 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeBodyData.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.powerflow; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link PowerFlowRealtimeBodyData} is responsible for storing + * the "Data" node of the {@link PowerFlowRealtimeBody}. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class PowerFlowRealtimeBodyData { + @SerializedName("Site") + private @Nullable PowerFlowRealtimeSite site; + + @SerializedName("Inverters") + private @Nullable Map inverters; + + public Map getInverters() { + Map localInverters = inverters; + if (localInverters == null) { + inverters = localInverters = new HashMap<>(); + } + return localInverters; + } + + public @Nullable PowerFlowRealtimeSite getSite() { + return site; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeInverter.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeInverter.java new file mode 100644 index 0000000000..fd0f042717 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeInverter.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.powerflow; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link PowerFlowRealtimeInverter} is responsible for storing + * the "Inverter" node of the {@link PowerFlowRealtimeBodyData}. + * + * @author Thomas Rokohl - Initial contribution + * @author Thomas Kordelle - Added inverter power, battery state of charge and PV solar yield + */ +public class PowerFlowRealtimeInverter { + @SerializedName("DT") + private double dt; + @SerializedName("P") + private double p; + @SerializedName("E_Day") + private double eDay; + @SerializedName("E_Year") + private double eYear; + @SerializedName("E_Total") + private double eTotal; + @SerializedName("Battery_Mode") + private String batteryMode; + @SerializedName("SOC") + private double soc; + + public double getDt() { + return dt; + } + + public double getP() { + return p; + } + + public double geteDay() { + return eDay; + } + + public double geteYear() { + return eYear; + } + + public double geteTotal() { + return eTotal; + } + + public String getBatteryMode() { + return batteryMode; + } + + public double getSoc() { + return soc; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeResponse.java new file mode 100644 index 0000000000..fb16896c03 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeResponse.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.powerflow; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.fronius.internal.api.dto.BaseFroniusResponse; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link PowerFlowRealtimeResponse} is responsible for storing + * the response from the GetPowerFlowRealtimeData response. + * + * @author Thomas Rokohl - Initial contribution + */ +@NonNullByDefault +public class PowerFlowRealtimeResponse extends BaseFroniusResponse { + @SerializedName("Body") + private @Nullable PowerFlowRealtimeBody body; + + public @Nullable PowerFlowRealtimeBody getBody() { + return body; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeSite.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeSite.java new file mode 100644 index 0000000000..a1df0a7ea9 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/powerflow/PowerFlowRealtimeSite.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.fronius.internal.api.dto.powerflow; + +import com.google.gson.annotations.SerializedName; + +/** + * The {@link PowerFlowRealtimeSite} is responsible for storing + * the "Site" node of the {@link PowerFlowRealtimeBodyData}. + * + * @author Thomas Rokohl - Initial contribution + */ +public class PowerFlowRealtimeSite { + @SerializedName("Mode") + private String mode; + @SerializedName("P_Grid") + private double pgrid; + @SerializedName("P_Load") + private double pload; + @SerializedName("P_Akku") + private double pakku; + @SerializedName("P_PV") + private double ppv; + @SerializedName("rel_SelfConsumption") + private double relSelfConsumption; + @SerializedName("rel_Autonomy") + private double relAutonomy; + @SerializedName("E_Day") + private double eDay; + @SerializedName("E_Year") + private double eYear; + @SerializedName("E_Total") + private double eTotal; + @SerializedName("Meter_Location") + private String meterLocation; + + public String getMode() { + if (mode == null) { + mode = ""; + } + return mode; + } + + public double getPgrid() { + return pgrid; + } + + public double getPload() { + return pload; + } + + public double getPakku() { + return pakku; + } + + public double getPpv() { + return ppv; + } + + public double getRelSelfConsumption() { + return relSelfConsumption; + } + + public double getRelAutonomy() { + return relAutonomy; + } + + public double geteDay() { + return eDay; + } + + public double geteYear() { + return eYear; + } + + public double geteTotal() { + return eTotal; + } + + public String getMeterLocation() { + return meterLocation; + } +} diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBaseThingHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBaseThingHandler.java index 24a40bac29..acf2917560 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBaseThingHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBaseThingHandler.java @@ -12,12 +12,17 @@ */ package org.openhab.binding.fronius.internal.handler; -import org.eclipse.jdt.annotation.NonNull; +import static org.openhab.binding.fronius.internal.FroniusBindingConstants.API_TIMEOUT; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.http.HttpMethod; import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; -import org.openhab.binding.fronius.internal.FroniusCommunicationException; -import org.openhab.binding.fronius.internal.FroniusHttpUtil; -import org.openhab.binding.fronius.internal.api.BaseFroniusResponse; -import org.openhab.binding.fronius.internal.api.HeadStatus; +import org.openhab.binding.fronius.internal.api.FroniusCommunicationException; +import org.openhab.binding.fronius.internal.api.FroniusHttpUtil; +import org.openhab.binding.fronius.internal.api.dto.BaseFroniusResponse; +import org.openhab.binding.fronius.internal.api.dto.Head; +import org.openhab.binding.fronius.internal.api.dto.HeadStatus; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; @@ -45,18 +50,17 @@ import com.google.gson.JsonSyntaxException; * Convert ValueUnit to QuantityType * Support NULL value */ +@NonNullByDefault public abstract class FroniusBaseThingHandler extends BaseThingHandler { - private static final int API_TIMEOUT = 5000; private final Logger logger = LoggerFactory.getLogger(FroniusBaseThingHandler.class); private final String serviceDescription; - private FroniusBridgeHandler bridgeHandler; private final Gson gson; public FroniusBaseThingHandler(Thing thing) { super(thing); - gson = new Gson(); serviceDescription = getDescription(); + gson = new Gson(); } @Override @@ -124,7 +128,7 @@ public abstract class FroniusBaseThingHandler extends BaseThingHandler { * @param channelId the id identifying the channel * @return the "new" associated value */ - protected abstract State getValue(String channelId); + protected abstract @Nullable State getValue(String channelId); /** * Called by the bridge to fetch data and update channels @@ -158,22 +162,27 @@ public abstract class FroniusBaseThingHandler extends BaseThingHandler { * @param url to request * @return the object representation of the json response */ - protected @NonNull T collectDataFromUrl(Class type, String url) + protected T collectDataFromUrl(Class type, String url) throws FroniusCommunicationException { try { int attempts = 1; while (true) { logger.trace("Fetching URL = {}", url); - String response = FroniusHttpUtil.executeUrl(url, API_TIMEOUT); + String response = FroniusHttpUtil.executeUrl(HttpMethod.GET, url, API_TIMEOUT); logger.trace("aqiResponse = {}", response); + @Nullable T result = gson.fromJson(response, type); if (result == null) { throw new FroniusCommunicationException("Empty json result"); } - HeadStatus status = result.getHead().getStatus(); - if (status.getCode() == 0) { + Head head = result.getHead(); + if (head == null) { + throw new FroniusCommunicationException("Empty head in json result"); + } + HeadStatus status = head.getStatus(); + if (status != null && status.getCode() == 0) { return result; } @@ -185,9 +194,11 @@ public abstract class FroniusBaseThingHandler extends BaseThingHandler { // "Reason" : "Transfer timeout.", // "UserMessage" : "" // }, - logger.debug("Error from Fronius attempt #{}: {} - {}", attempts, status.getCode(), status.getReason()); + int code = status != null ? status.getCode() : 255; + String reason = status != null ? status.getReason() : "undefined runtime error"; + logger.debug("Error from Fronius attempt #{}: {} - {}", attempts, code, reason); if (attempts >= 3) { - throw new FroniusCommunicationException(status.getReason()); + throw new FroniusCommunicationException(reason); } Thread.sleep(500 * attempts); attempts++; diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java index 107489fba2..e6df0b5e5a 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.fronius.internal.handler; +import static org.openhab.binding.fronius.internal.FroniusBindingConstants.API_TIMEOUT; + import java.util.HashSet; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -19,9 +21,10 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.http.HttpMethod; import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; -import org.openhab.binding.fronius.internal.FroniusCommunicationException; -import org.openhab.binding.fronius.internal.FroniusHttpUtil; +import org.openhab.binding.fronius.internal.api.FroniusCommunicationException; +import org.openhab.binding.fronius.internal.api.FroniusHttpUtil; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -85,8 +88,9 @@ public class FroniusBridgeHandler extends BaseBridgeHandler { @Override public void dispose() { - if (refreshJob != null) { - refreshJob.cancel(true); + ScheduledFuture localRefreshJob = refreshJob; + if (localRefreshJob != null) { + localRefreshJob.cancel(true); refreshJob = null; } } @@ -108,8 +112,9 @@ public class FroniusBridgeHandler extends BaseBridgeHandler { } private void restartAutomaticRefresh() { - if (refreshJob != null) { // refreshJob should be null if the config isn't valid - refreshJob.cancel(false); + ScheduledFuture localRefreshJob = refreshJob; + if (localRefreshJob != null) { // refreshJob should be null if the config isn't valid + localRefreshJob.cancel(false); startAutomaticRefresh(); } } @@ -118,7 +123,8 @@ public class FroniusBridgeHandler extends BaseBridgeHandler { * Start the job refreshing the data */ private void startAutomaticRefresh() { - if (refreshJob == null || refreshJob.isCancelled()) { + ScheduledFuture localRefreshJob = refreshJob; + if (localRefreshJob == null || localRefreshJob.isCancelled()) { final FroniusBridgeConfiguration config = getConfigAs(FroniusBridgeConfiguration.class); Runnable runnable = () -> { try { @@ -140,6 +146,6 @@ public class FroniusBridgeHandler extends BaseBridgeHandler { } private void checkBridgeOnline(FroniusBridgeConfiguration config) throws FroniusCommunicationException { - FroniusHttpUtil.executeUrl("http://" + config.hostname, 5000); + FroniusHttpUtil.executeUrl(HttpMethod.GET, "http://" + config.hostname, API_TIMEOUT); } } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java index d0d004d36b..9818200ab9 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusMeterHandler.java @@ -14,12 +14,15 @@ package org.openhab.binding.fronius.internal.handler; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration; import org.openhab.binding.fronius.internal.FroniusBindingConstants; import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; -import org.openhab.binding.fronius.internal.FroniusCommunicationException; -import org.openhab.binding.fronius.internal.api.MeterRealtimeBodyDataDTO; -import org.openhab.binding.fronius.internal.api.MeterRealtimeResponseDTO; +import org.openhab.binding.fronius.internal.api.FroniusCommunicationException; +import org.openhab.binding.fronius.internal.api.dto.meter.MeterRealtimeBody; +import org.openhab.binding.fronius.internal.api.dto.meter.MeterRealtimeBodyData; +import org.openhab.binding.fronius.internal.api.dto.meter.MeterRealtimeDetails; +import org.openhab.binding.fronius.internal.api.dto.meter.MeterRealtimeResponse; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; @@ -36,7 +39,7 @@ import org.openhab.core.types.State; */ public class FroniusMeterHandler extends FroniusBaseThingHandler { - private MeterRealtimeBodyDataDTO meterRealtimeBodyData; + private @Nullable MeterRealtimeBodyData meterRealtimeBodyData; private FroniusBaseDeviceConfiguration config; public FroniusMeterHandler(Thing thing) { @@ -69,7 +72,8 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { */ @Override protected State getValue(String channelId) { - if (meterRealtimeBodyData == null) { + MeterRealtimeBodyData localMeterRealtimeBodyData = meterRealtimeBodyData; + if (localMeterRealtimeBodyData == null) { return null; } @@ -81,39 +85,39 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { switch (fieldName) { case FroniusBindingConstants.METER_ENABLE: - return new DecimalType(meterRealtimeBodyData.getEnable()); + return new DecimalType(localMeterRealtimeBodyData.getEnable()); case FroniusBindingConstants.METER_LOCATION: - return new DecimalType(meterRealtimeBodyData.getMeterLocationCurrent()); + return new DecimalType(localMeterRealtimeBodyData.getMeterLocationCurrent()); case FroniusBindingConstants.METER_CURRENT_AC_PHASE_1: - return new QuantityType<>(meterRealtimeBodyData.getCurrentACPhase1(), Units.AMPERE); + return new QuantityType<>(localMeterRealtimeBodyData.getCurrentACPhase1(), Units.AMPERE); case FroniusBindingConstants.METER_CURRENT_AC_PHASE_2: - return new QuantityType<>(meterRealtimeBodyData.getCurrentACPhase2(), Units.AMPERE); + return new QuantityType<>(localMeterRealtimeBodyData.getCurrentACPhase2(), Units.AMPERE); case FroniusBindingConstants.METER_CURRENT_AC_PHASE_3: - return new QuantityType<>(meterRealtimeBodyData.getCurrentACPhase3(), Units.AMPERE); + return new QuantityType<>(localMeterRealtimeBodyData.getCurrentACPhase3(), Units.AMPERE); case FroniusBindingConstants.METER_VOLTAGE_AC_PHASE_1: - return new QuantityType<>(meterRealtimeBodyData.getVoltageACPhase1(), Units.VOLT); + return new QuantityType<>(localMeterRealtimeBodyData.getVoltageACPhase1(), Units.VOLT); case FroniusBindingConstants.METER_VOLTAGE_AC_PHASE_2: - return new QuantityType<>(meterRealtimeBodyData.getVoltageACPhase2(), Units.VOLT); + return new QuantityType<>(localMeterRealtimeBodyData.getVoltageACPhase2(), Units.VOLT); case FroniusBindingConstants.METER_VOLTAGE_AC_PHASE_3: - return new QuantityType<>(meterRealtimeBodyData.getVoltageACPhase3(), Units.VOLT); + return new QuantityType<>(localMeterRealtimeBodyData.getVoltageACPhase3(), Units.VOLT); case FroniusBindingConstants.METER_POWER_PHASE_1: - return new QuantityType<>(meterRealtimeBodyData.getPowerRealPPhase1(), Units.WATT); + return new QuantityType<>(localMeterRealtimeBodyData.getPowerRealPPhase1(), Units.WATT); case FroniusBindingConstants.METER_POWER_PHASE_2: - return new QuantityType<>(meterRealtimeBodyData.getPowerRealPPhase2(), Units.WATT); + return new QuantityType<>(localMeterRealtimeBodyData.getPowerRealPPhase2(), Units.WATT); case FroniusBindingConstants.METER_POWER_PHASE_3: - return new QuantityType<>(meterRealtimeBodyData.getPowerRealPPhase3(), Units.WATT); + return new QuantityType<>(localMeterRealtimeBodyData.getPowerRealPPhase3(), Units.WATT); case FroniusBindingConstants.METER_POWER_SUM: - return new QuantityType<>(meterRealtimeBodyData.getPowerRealPSum(), Units.WATT); + return new QuantityType<>(localMeterRealtimeBodyData.getPowerRealPSum(), Units.WATT); case FroniusBindingConstants.METER_POWER_FACTOR_PHASE_1: - return new DecimalType(meterRealtimeBodyData.getPowerFactorPhase1()); + return new DecimalType(localMeterRealtimeBodyData.getPowerFactorPhase1()); case FroniusBindingConstants.METER_POWER_FACTOR_PHASE_2: - return new DecimalType(meterRealtimeBodyData.getPowerFactorPhase2()); + return new DecimalType(localMeterRealtimeBodyData.getPowerFactorPhase2()); case FroniusBindingConstants.METER_POWER_FACTOR_PHASE_3: - return new DecimalType(meterRealtimeBodyData.getPowerFactorPhase3()); + return new DecimalType(localMeterRealtimeBodyData.getPowerFactorPhase3()); case FroniusBindingConstants.METER_ENERGY_REAL_SUM_CONSUMED: - return new QuantityType<>(meterRealtimeBodyData.getEnergyRealWACSumConsumed(), Units.WATT_HOUR); + return new QuantityType<>(localMeterRealtimeBodyData.getEnergyRealWACSumConsumed(), Units.WATT_HOUR); case FroniusBindingConstants.METER_ENERGY_REAL_SUM_PRODUCED: - return new QuantityType<>(meterRealtimeBodyData.getEnergyRealWACSumProduced(), Units.WATT_HOUR); + return new QuantityType<>(localMeterRealtimeBodyData.getEnergyRealWACSumProduced(), Units.WATT_HOUR); default: break; } @@ -122,14 +126,19 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { } private void updateProperties() { - if (meterRealtimeBodyData == null) { + MeterRealtimeBodyData localMeterRealtimeBodyData = meterRealtimeBodyData; + if (localMeterRealtimeBodyData == null) { + return; + } + MeterRealtimeDetails details = localMeterRealtimeBodyData.getDetails(); + if (details == null) { return; } Map properties = editProperties(); - properties.put(Thing.PROPERTY_MODEL_ID, meterRealtimeBodyData.getDetails().getModel()); - properties.put(Thing.PROPERTY_SERIAL_NUMBER, meterRealtimeBodyData.getDetails().getSerial()); + properties.put(Thing.PROPERTY_MODEL_ID, details.getModel()); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, details.getSerial()); updateProperties(properties); } @@ -139,9 +148,14 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { */ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusBaseDeviceConfiguration config) throws FroniusCommunicationException { - MeterRealtimeResponseDTO meterRealtimeResponse = getMeterRealtimeData(bridgeConfiguration.hostname, + MeterRealtimeResponse meterRealtimeResponse = getMeterRealtimeData(bridgeConfiguration.hostname, config.deviceId); - meterRealtimeBodyData = meterRealtimeResponse.getBody().getData(); + MeterRealtimeBody meterRealtimeBody = meterRealtimeResponse.getBody(); + if (meterRealtimeBody == null) { + meterRealtimeBodyData = null; + return; + } + meterRealtimeBodyData = meterRealtimeBody.getData(); } /** @@ -151,9 +165,8 @@ public class FroniusMeterHandler extends FroniusBaseThingHandler { * @param deviceId of the device * @return {MeterRealtimeResponse} the object representation of the json response */ - private MeterRealtimeResponseDTO getMeterRealtimeData(String ip, int deviceId) - throws FroniusCommunicationException { + private MeterRealtimeResponse getMeterRealtimeData(String ip, int deviceId) throws FroniusCommunicationException { String location = FroniusBindingConstants.getMeterDataUrl(ip, deviceId); - return collectDataFromUrl(MeterRealtimeResponseDTO.class, location); + return collectDataFromUrl(MeterRealtimeResponse.class, location); } } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java index 09eef22211..2e9328ca12 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusOhmpilotHandler.java @@ -14,12 +14,15 @@ package org.openhab.binding.fronius.internal.handler; import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration; import org.openhab.binding.fronius.internal.FroniusBindingConstants; import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; -import org.openhab.binding.fronius.internal.FroniusCommunicationException; -import org.openhab.binding.fronius.internal.api.OhmpilotRealtimeBodyDataDTO; -import org.openhab.binding.fronius.internal.api.OhmpilotRealtimeResponseDTO; +import org.openhab.binding.fronius.internal.api.FroniusCommunicationException; +import org.openhab.binding.fronius.internal.api.dto.ohmpilot.OhmpilotRealtimeBody; +import org.openhab.binding.fronius.internal.api.dto.ohmpilot.OhmpilotRealtimeBodyData; +import org.openhab.binding.fronius.internal.api.dto.ohmpilot.OhmpilotRealtimeDetails; +import org.openhab.binding.fronius.internal.api.dto.ohmpilot.OhmpilotRealtimeResponse; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; @@ -35,7 +38,7 @@ import org.openhab.core.types.State; */ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { - private OhmpilotRealtimeBodyDataDTO ohmpilotRealtimeBodyData; + private @Nullable OhmpilotRealtimeBodyData ohmpilotRealtimeBodyData; private FroniusBaseDeviceConfiguration config; public FroniusOhmpilotHandler(Thing thing) { @@ -68,7 +71,8 @@ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { */ @Override protected State getValue(String channelId) { - if (ohmpilotRealtimeBodyData == null) { + OhmpilotRealtimeBodyData localOhmpilotRealtimeBodyData = ohmpilotRealtimeBodyData; + if (localOhmpilotRealtimeBodyData == null) { return null; } @@ -80,15 +84,15 @@ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { switch (fieldName) { case FroniusBindingConstants.OHMPILOT_POWER_REAL_SUM: - return new QuantityType<>(ohmpilotRealtimeBodyData.getPowerPACSum(), Units.WATT); + return new QuantityType<>(localOhmpilotRealtimeBodyData.getPowerPACSum(), Units.WATT); case FroniusBindingConstants.OHMPILOT_ENERGY_REAL_SUM_CONSUMED: - return new QuantityType<>(ohmpilotRealtimeBodyData.getEnergyRealWACSumConsumed(), Units.WATT_HOUR); + return new QuantityType<>(localOhmpilotRealtimeBodyData.getEnergyRealWACSumConsumed(), Units.WATT_HOUR); case FroniusBindingConstants.OHMPILOT_ENERGY_SENSOR_TEMPERATURE_CHANNEL_1: - return new QuantityType<>(ohmpilotRealtimeBodyData.getTemperatureChannel1(), Units.KELVIN); + return new QuantityType<>(localOhmpilotRealtimeBodyData.getTemperatureChannel1(), Units.KELVIN); case FroniusBindingConstants.OHMPILOT_STATE_CODE: - return new DecimalType(ohmpilotRealtimeBodyData.getStateCode()); + return new DecimalType(localOhmpilotRealtimeBodyData.getStateCode()); case FroniusBindingConstants.OHMPILOT_ERROR_CODE: - return new DecimalType(ohmpilotRealtimeBodyData.getErrorCode()); + return new DecimalType(localOhmpilotRealtimeBodyData.getErrorCode()); default: break; @@ -98,14 +102,19 @@ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { } private void updateProperties() { - if (ohmpilotRealtimeBodyData == null) { + OhmpilotRealtimeBodyData localOhmpilotRealtimeBodyData = ohmpilotRealtimeBodyData; + if (localOhmpilotRealtimeBodyData == null) { + return; + } + OhmpilotRealtimeDetails details = localOhmpilotRealtimeBodyData.getDetails(); + if (details == null) { return; } Map properties = editProperties(); - properties.put(Thing.PROPERTY_MODEL_ID, ohmpilotRealtimeBodyData.getDetails().getModel()); - properties.put(Thing.PROPERTY_SERIAL_NUMBER, ohmpilotRealtimeBodyData.getDetails().getSerial()); + properties.put(Thing.PROPERTY_MODEL_ID, details.getModel()); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, details.getSerial()); updateProperties(properties); } @@ -115,9 +124,14 @@ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { */ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusBaseDeviceConfiguration config) throws FroniusCommunicationException { - OhmpilotRealtimeResponseDTO ohmpilotRealtimeResponse = getOhmpilotRealtimeData(bridgeConfiguration.hostname, + OhmpilotRealtimeResponse ohmpilotRealtimeResponse = getOhmpilotRealtimeData(bridgeConfiguration.hostname, config.deviceId); - ohmpilotRealtimeBodyData = ohmpilotRealtimeResponse.getBody().getData(); + OhmpilotRealtimeBody ohmpilotRealtimeBody = ohmpilotRealtimeResponse.getBody(); + if (ohmpilotRealtimeBody == null) { + ohmpilotRealtimeBodyData = null; + return; + } + ohmpilotRealtimeBodyData = ohmpilotRealtimeBody.getData(); } /** @@ -127,9 +141,9 @@ public class FroniusOhmpilotHandler extends FroniusBaseThingHandler { * @param deviceId of the device * @return {OhmpilotRealtimeResponse} the object representation of the json response */ - private OhmpilotRealtimeResponseDTO getOhmpilotRealtimeData(String ip, int deviceId) + private OhmpilotRealtimeResponse getOhmpilotRealtimeData(String ip, int deviceId) throws FroniusCommunicationException { String location = FroniusBindingConstants.getOhmPilotDataUrl(ip, deviceId); - return collectDataFromUrl(OhmpilotRealtimeResponseDTO.class, location); + return collectDataFromUrl(OhmpilotRealtimeResponse.class, location); } } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusSymoInverterHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusSymoInverterHandler.java index 7461b29c50..803009756c 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusSymoInverterHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusSymoInverterHandler.java @@ -16,23 +16,26 @@ import java.util.Optional; import javax.measure.Unit; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.fronius.internal.FroniusBaseDeviceConfiguration; import org.openhab.binding.fronius.internal.FroniusBindingConstants; import org.openhab.binding.fronius.internal.FroniusBridgeConfiguration; -import org.openhab.binding.fronius.internal.FroniusCommunicationException; -import org.openhab.binding.fronius.internal.api.InverterRealtimeBodyData; -import org.openhab.binding.fronius.internal.api.InverterRealtimeResponse; -import org.openhab.binding.fronius.internal.api.PowerFlowRealtimeInverter; -import org.openhab.binding.fronius.internal.api.PowerFlowRealtimeResponse; -import org.openhab.binding.fronius.internal.api.PowerFlowRealtimeSite; -import org.openhab.binding.fronius.internal.api.ValueUnit; +import org.openhab.binding.fronius.internal.api.FroniusCommunicationException; +import org.openhab.binding.fronius.internal.api.dto.ValueUnit; +import org.openhab.binding.fronius.internal.api.dto.inverter.InverterDeviceStatus; +import org.openhab.binding.fronius.internal.api.dto.inverter.InverterRealtimeBody; +import org.openhab.binding.fronius.internal.api.dto.inverter.InverterRealtimeBodyData; +import org.openhab.binding.fronius.internal.api.dto.inverter.InverterRealtimeResponse; +import org.openhab.binding.fronius.internal.api.dto.powerflow.PowerFlowRealtimeBody; +import org.openhab.binding.fronius.internal.api.dto.powerflow.PowerFlowRealtimeBodyData; +import org.openhab.binding.fronius.internal.api.dto.powerflow.PowerFlowRealtimeInverter; +import org.openhab.binding.fronius.internal.api.dto.powerflow.PowerFlowRealtimeResponse; +import org.openhab.binding.fronius.internal.api.dto.powerflow.PowerFlowRealtimeSite; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.Units; import org.openhab.core.thing.Thing; import org.openhab.core.types.State; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * The {@link FroniusSymoInverterHandler} is responsible for updating the data, which are @@ -45,9 +48,8 @@ import org.slf4j.LoggerFactory; */ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler { - private final Logger logger = LoggerFactory.getLogger(FroniusSymoInverterHandler.class); - private InverterRealtimeResponse inverterRealtimeResponse; - private PowerFlowRealtimeResponse powerFlowResponse; + private @Nullable InverterRealtimeResponse inverterRealtimeResponse; + private @Nullable PowerFlowRealtimeResponse powerFlowResponse; private FroniusBaseDeviceConfiguration config; public FroniusSymoInverterHandler(Thing thing) { @@ -85,84 +87,131 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler { } final String fieldName = fields[0]; - if (inverterRealtimeResponse != null) { - InverterRealtimeBodyData inverterData = inverterRealtimeResponse.getBody().getData(); - switch (fieldName) { - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PAC: - return getQuantityOrZero(inverterData.getPac(), Units.WATT); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_FAC: - return getQuantityOrZero(inverterData.getFac(), Units.HERTZ); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IAC: - return getQuantityOrZero(inverterData.getIac(), Units.AMPERE); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC: - return getQuantityOrZero(inverterData.getIdc(), Units.AMPERE); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC2: - return getQuantityOrZero(inverterData.getIdc2(), Units.AMPERE); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC3: - return getQuantityOrZero(inverterData.getIdc3(), Units.AMPERE); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UAC: - return getQuantityOrZero(inverterData.getUac(), Units.VOLT); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC: - return getQuantityOrZero(inverterData.getUdc(), Units.VOLT); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC2: - return getQuantityOrZero(inverterData.getUdc2(), Units.VOLT); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC3: - return getQuantityOrZero(inverterData.getUdc3(), Units.VOLT); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC: - return calculatePower(inverterData.getUdc(), inverterData.getIdc()); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC2: - return calculatePower(inverterData.getUdc2(), inverterData.getIdc2()); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC3: - return calculatePower(inverterData.getUdc3(), inverterData.getIdc3()); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DAY_ENERGY: - // Convert the unit to kWh for backwards compatibility with non-quantity type - return getQuantityOrZero(inverterData.getDayEnergy(), Units.KILOWATT_HOUR).toUnit("kWh"); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_TOTAL: - // Convert the unit to MWh for backwards compatibility with non-quantity type - return getQuantityOrZero(inverterData.getTotalEnergy(), Units.MEGAWATT_HOUR).toUnit("MWh"); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_YEAR: - // Convert the unit to MWh for backwards compatibility with non-quantity type - return getQuantityOrZero(inverterData.getYearEnergy(), Units.MEGAWATT_HOUR).toUnit("MWh"); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DEVICE_STATUS_ERROR_CODE: - return new DecimalType(inverterData.getDeviceStatus().getErrorCode()); - case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DEVICE_STATUS_STATUS_CODE: - return new DecimalType(inverterData.getDeviceStatus().getStatusCode()); - default: - break; - } + InverterRealtimeBodyData inverterData = getInverterData(); + if (inverterData == null) { + return null; + } + + switch (fieldName) { + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PAC: + return getQuantityOrZero(inverterData.getPac(), Units.WATT); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_FAC: + return getQuantityOrZero(inverterData.getFac(), Units.HERTZ); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IAC: + return getQuantityOrZero(inverterData.getIac(), Units.AMPERE); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC: + return getQuantityOrZero(inverterData.getIdc(), Units.AMPERE); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC2: + return getQuantityOrZero(inverterData.getIdc2(), Units.AMPERE); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_IDC3: + return getQuantityOrZero(inverterData.getIdc3(), Units.AMPERE); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UAC: + return getQuantityOrZero(inverterData.getUac(), Units.VOLT); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC: + return getQuantityOrZero(inverterData.getUdc(), Units.VOLT); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC2: + return getQuantityOrZero(inverterData.getUdc2(), Units.VOLT); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_UDC3: + return getQuantityOrZero(inverterData.getUdc3(), Units.VOLT); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC: + return calculatePower(inverterData.getUdc(), inverterData.getIdc()); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC2: + return calculatePower(inverterData.getUdc2(), inverterData.getIdc2()); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_PDC3: + return calculatePower(inverterData.getUdc3(), inverterData.getIdc3()); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DAY_ENERGY: + // Convert the unit to kWh for backwards compatibility with non-quantity type + return getQuantityOrZero(inverterData.getDayEnergy(), Units.KILOWATT_HOUR).toUnit("kWh"); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_TOTAL: + // Convert the unit to MWh for backwards compatibility with non-quantity type + return getQuantityOrZero(inverterData.getTotalEnergy(), Units.MEGAWATT_HOUR).toUnit("MWh"); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_YEAR: + // Convert the unit to MWh for backwards compatibility with non-quantity type + return getQuantityOrZero(inverterData.getYearEnergy(), Units.MEGAWATT_HOUR).toUnit("MWh"); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DEVICE_STATUS_ERROR_CODE: + InverterDeviceStatus deviceStatus = inverterData.getDeviceStatus(); + if (deviceStatus == null) { + return null; + } + return new DecimalType(deviceStatus.getErrorCode()); + case FroniusBindingConstants.INVERTER_DATA_CHANNEL_DEVICE_STATUS_STATUS_CODE: + deviceStatus = inverterData.getDeviceStatus(); + if (deviceStatus == null) { + return null; + } + return new DecimalType(deviceStatus.getStatusCode()); + default: + break; } - if (powerFlowResponse != null) { - PowerFlowRealtimeSite site = powerFlowResponse.getBody().getData().getSite(); - switch (fieldName) { - case FroniusBindingConstants.POWER_FLOW_P_GRID: - return new QuantityType<>(site.getPgrid(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_P_LOAD: - return new QuantityType<>(site.getPload(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_P_AKKU: - return new QuantityType<>(site.getPakku(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_P_PV: - return new QuantityType<>(site.getPpv(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_AUTONOMY: - return new QuantityType<>(site.getRelAutonomy(), Units.PERCENT); - case FroniusBindingConstants.POWER_FLOW_SELF_CONSUMPTION: - return new QuantityType<>(site.getRelSelfConsumption(), Units.PERCENT); - case FroniusBindingConstants.POWER_FLOW_INVERTER_POWER: - return new QuantityType<>(getInverter(config.deviceId).getP(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_INVERTER_SOC: - return new QuantityType<>(getInverter(config.deviceId).getSoc(), Units.PERCENT); - - // Kept for backwards compatibility - case FroniusBindingConstants.POWER_FLOW_INVERTER_1_POWER: - return new QuantityType<>(getInverter(1).getP(), Units.WATT); - case FroniusBindingConstants.POWER_FLOW_INVERTER_1_SOC: - return new QuantityType<>(getInverter(1).getSoc(), Units.PERCENT); - default: - break; + PowerFlowRealtimeBodyData powerFlowData = getPowerFlowRealtimeData(); + if (powerFlowData == null) { + return null; + } + PowerFlowRealtimeSite site = powerFlowData.getSite(); + if (site == null) { + return null; + } + + return switch (fieldName) { + case FroniusBindingConstants.POWER_FLOW_P_GRID -> new QuantityType<>(site.getPgrid(), Units.WATT); + case FroniusBindingConstants.POWER_FLOW_P_LOAD -> new QuantityType<>(site.getPload(), Units.WATT); + case FroniusBindingConstants.POWER_FLOW_P_AKKU -> new QuantityType<>(site.getPakku(), Units.WATT); + case FroniusBindingConstants.POWER_FLOW_P_PV -> new QuantityType<>(site.getPpv(), Units.WATT); + case FroniusBindingConstants.POWER_FLOW_AUTONOMY -> + new QuantityType<>(site.getRelAutonomy(), Units.PERCENT); + case FroniusBindingConstants.POWER_FLOW_SELF_CONSUMPTION -> + new QuantityType<>(site.getRelSelfConsumption(), Units.PERCENT); + case FroniusBindingConstants.POWER_FLOW_INVERTER_POWER -> { + PowerFlowRealtimeInverter inverter = getInverter(config.deviceId); + if (inverter == null) { + yield null; + } + yield new QuantityType<>(inverter.getP(), Units.WATT); + } + case FroniusBindingConstants.POWER_FLOW_INVERTER_SOC -> { + PowerFlowRealtimeInverter inverter = getInverter(config.deviceId); + if (inverter == null) { + yield null; + } + yield new QuantityType<>(inverter.getSoc(), Units.PERCENT); + } + // Kept for backwards compatibility + case FroniusBindingConstants.POWER_FLOW_INVERTER_1_POWER -> { + PowerFlowRealtimeInverter inverter = getInverter(1); + if (inverter == null) { + yield null; + } + yield new QuantityType<>(inverter.getP(), Units.WATT); } + case FroniusBindingConstants.POWER_FLOW_INVERTER_1_SOC -> { + PowerFlowRealtimeInverter inverter = getInverter(1); + if (inverter == null) { + yield null; + } + yield new QuantityType<>(inverter.getSoc(), Units.PERCENT); + } + + default -> null; + }; + } + + private @Nullable InverterRealtimeBodyData getInverterData() { + InverterRealtimeResponse localInverterRealtimeResponse = inverterRealtimeResponse; + if (localInverterRealtimeResponse == null) { + return null; } + InverterRealtimeBody inverterBody = localInverterRealtimeResponse.getBody(); + return (inverterBody != null) ? inverterBody.getData() : null; + } - return null; + private @Nullable PowerFlowRealtimeBodyData getPowerFlowRealtimeData() { + PowerFlowRealtimeResponse localPowerFlowResponse = powerFlowResponse; + if (localPowerFlowResponse == null) { + return null; + } + PowerFlowRealtimeBody powerFlowBody = localPowerFlowResponse.getBody(); + return (powerFlowBody != null) ? powerFlowBody.getData() : null; } /** @@ -171,8 +220,12 @@ public class FroniusSymoInverterHandler extends FroniusBaseThingHandler { * @param number The inverter object of the given index * @return a PowerFlowRealtimeInverter object. */ - private PowerFlowRealtimeInverter getInverter(final int number) { - return powerFlowResponse.getBody().getData().getInverters().get(Integer.toString(number)); + private @Nullable PowerFlowRealtimeInverter getInverter(final int number) { + PowerFlowRealtimeBodyData powerFlowData = getPowerFlowRealtimeData(); + if (powerFlowData == null) { + return null; + } + return powerFlowData.getInverters().get(Integer.toString(number)); } /**