[fronius] Verify battery control time of use successfully set (#18131)

Signed-off-by: Florian Hotze <dev@florianhotze.com>
main
Florian Hotze 2025-01-19 22:01:05 +01:00 committed by GitHub
parent 8f77e16e18
commit d0b918e448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -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");
}

View File

@ -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 <code>/config</code> endpoint.
*
* @author Florian Hotze - Initial contribution
*/
public record PostConfigResponse(List<String> errors, List<String> permissionFailure, List<String> unknownNodes,
List<String> validationErrors, List<String> writeFailure, List<String> writeSuccess) {
}