Skip to content

Commit

Permalink
[fronius] Verify battery control time of use successfully set (#18131)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Hotze <dev@florianhotze.com>
  • Loading branch information
florian-h05 authored Jan 19, 2025
1 parent 8f77e16 commit d0b918e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -120,8 +121,13 @@ private void setTimeOfUse(TimeOfUseRecords records)

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}

0 comments on commit d0b918e

Please sign in to comment.