From d0b918e448186a46228332131be75162b4b30d4d Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Sun, 19 Jan 2025 22:01:05 +0100 Subject: [PATCH] [fronius] Verify battery control time of use successfully set (#18131) Signed-off-by: Florian Hotze --- .../internal/api/FroniusBatteryControl.java | 8 ++++++- .../api/dto/inverter/PostConfigResponse.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/PostConfigResponse.java diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusBatteryControl.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusBatteryControl.java index 4eb2cc80658..3fc38c76cc3 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusBatteryControl.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/FroniusBatteryControl.java @@ -26,6 +26,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; +import org.openhab.binding.fronius.internal.api.dto.inverter.PostConfigResponse; import org.openhab.binding.fronius.internal.api.dto.inverter.batterycontrol.ScheduleType; import org.openhab.binding.fronius.internal.api.dto.inverter.batterycontrol.TimeOfUseRecord; import org.openhab.binding.fronius.internal.api.dto.inverter.batterycontrol.TimeOfUseRecords; @@ -120,8 +121,13 @@ public class FroniusBatteryControl { // Set the time of use settings String json = gson.toJson(records); - FroniusHttpUtil.executeUrl(HttpMethod.POST, timeOfUseUri.toString(), headers, + String responseString = FroniusHttpUtil.executeUrl(HttpMethod.POST, timeOfUseUri.toString(), headers, new ByteArrayInputStream(json.getBytes()), "application/json", API_TIMEOUT); + PostConfigResponse response = gson.fromJson(responseString, PostConfigResponse.class); + if (!response.writeSuccess().contains("timeofuse")) { + LOGGER.debug("{}", responseString); + throw new FroniusCommunicationException("Failed to write configuration to inverter"); + } LOGGER.trace("Time of Use settings set successfully"); } diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/PostConfigResponse.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/PostConfigResponse.java new file mode 100644 index 00000000000..7949d8b01c5 --- /dev/null +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/api/dto/inverter/PostConfigResponse.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010-2025 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 java.util.List; + +/** + * Record representing the response of a POST request to a /config endpoint. + * + * @author Florian Hotze - Initial contribution + */ +public record PostConfigResponse(List errors, List permissionFailure, List unknownNodes, + List validationErrors, List writeFailure, List writeSuccess) { +}