Skip to content

Commit

Permalink
SimulatorApp: fix bug related to creation of Ess.Power component (#2722)
Browse files Browse the repository at this point in the history
The Ess.Power component is actually never deleted. An attempt to delete it, is ignored. I was not able to find out the reason for that.
Since the component is created afterwards again, this change ensures, the component is updated with the desired `enablePid` property.

Co-authored-by: Felix Remmel <[email protected]>
  • Loading branch information
parapluplu and Felix Remmel authored Jul 31, 2024
1 parent ebcf244 commit 062d960
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
Expand Down Expand Up @@ -43,7 +42,6 @@
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.CreateComponentConfigRequest;
import io.openems.common.jsonrpc.request.DeleteComponentConfigRequest;
import io.openems.common.jsonrpc.request.UpdateComponentConfigRequest.Property;
import io.openems.common.session.Role;
import io.openems.common.test.TimeLeapClock;
import io.openems.common.timedata.Resolution;
Expand Down Expand Up @@ -182,8 +180,7 @@ private synchronized CompletableFuture<ExecuteSimulationResponse> handleExecuteS
this.setCycleTime(AbstractWorker.ALWAYS_WAIT_FOR_TRIGGER_NEXT_RUN);

// Create Ess.Power with disabled PID filter
this.componentManager.handleCreateComponentConfigRequest(user,
new CreateComponentConfigRequest("Ess.Power", Arrays.asList(new Property("enablePid", false))));
this.updateEssPower();

// Create Components
Set<String> simulatorComponentIds = new HashSet<>();
Expand Down Expand Up @@ -328,7 +325,11 @@ private void deleteAllConfigurations(User user) throws OpenemsNamedException {
}
if (factoryPid.startsWith("Core.") //
|| factoryPid.startsWith("Controller.Api.") //
|| factoryPid.startsWith("Predictor.")) {
|| factoryPid.startsWith("Predictor.") //
// Ess.Power exists by default. We don't delete it, but will overwrite the
// configuration later. Delete request for this component does not work for some
// unknown reason.
|| factoryPid.equals("Ess.Power")) {
continue;
}
switch (factoryPid) {
Expand Down Expand Up @@ -401,6 +402,22 @@ private void setCycleTime(int cycleTime) {
}
}

/**
* Sets the Ess.Power to the default settings for a simulation.
*
*/
private void updateEssPower() {
try {
var config = this.cm.getConfiguration("Ess.Power", null);
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("enablePid", false);
config.update(properties);
} catch (IOException e) {
this.logError(this.log,
"Unable to configure Ess.Power enabledPid. " + e.getClass() + ": " + e.getMessage());
}
}

private void waitForComponentsToActivate(Set<String> simulatorComponentIds) throws OpenemsException {
// Wait for Components to appear
for (var i = 0; i < 100; i++) {
Expand Down

0 comments on commit 062d960

Please sign in to comment.