Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix SimulatorApp bug related to creation of Ess.Power component #2722

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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();

Check warning on line 183 in io.openems.edge.simulator/src/io/openems/edge/simulator/app/SimulatorAppImpl.java

View check run for this annotation

Codecov / codecov/patch

io.openems.edge.simulator/src/io/openems/edge/simulator/app/SimulatorAppImpl.java#L183

Added line #L183 was not covered by tests

// Create Components
Set<String> simulatorComponentIds = new HashSet<>();
Expand Down Expand Up @@ -328,7 +325,11 @@
}
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 @@
}
}

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

Check warning on line 419 in io.openems.edge.simulator/src/io/openems/edge/simulator/app/SimulatorAppImpl.java

View check run for this annotation

Codecov / codecov/patch

io.openems.edge.simulator/src/io/openems/edge/simulator/app/SimulatorAppImpl.java#L411-L419

Added lines #L411 - L419 were not covered by tests

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