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-Active-Power-Controller: Refactor + add UI Widget #1325

Merged
merged 3 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions io.openems.edge.application/EdgeApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
bnd.identity;id='io.openems.edge.controller.ess.activepowervoltagecharacteristic',\
bnd.identity;id='io.openems.edge.controller.ess.delaycharge',\
bnd.identity;id='io.openems.edge.controller.ess.delayedselltogrid',\
bnd.identity;id='io.openems.edge.controller.ess.fixactivepower',\
bnd.identity;id='io.openems.edge.controller.ess.hybrid.surplusfeedtogrid',\
bnd.identity;id='io.openems.edge.controller.ess.limittotaldischarge',\
bnd.identity;id='io.openems.edge.controller.ess.mindischargeperiod',\
Expand All @@ -77,7 +78,6 @@
bnd.identity;id='io.openems.edge.controller.pvinverter.selltogridlimit',\
bnd.identity;id='io.openems.edge.controller.symmetric.balancing',\
bnd.identity;id='io.openems.edge.controller.symmetric.balancingschedule',\
bnd.identity;id='io.openems.edge.controller.symmetric.fixactivepower',\
bnd.identity;id='io.openems.edge.controller.symmetric.fixreactivepower',\
bnd.identity;id='io.openems.edge.controller.symmetric.limitactivepower',\
bnd.identity;id='io.openems.edge.controller.symmetric.linearpowerband',\
Expand Down Expand Up @@ -184,6 +184,7 @@
io.openems.edge.controller.ess.activepowervoltagecharacteristic;version=snapshot,\
io.openems.edge.controller.ess.delaycharge;version=snapshot,\
io.openems.edge.controller.ess.delayedselltogrid;version=snapshot,\
io.openems.edge.controller.ess.fixactivepower;version=snapshot,\
io.openems.edge.controller.ess.hybrid.surplusfeedtogrid;version=snapshot,\
io.openems.edge.controller.ess.limittotaldischarge;version=snapshot,\
io.openems.edge.controller.ess.mindischargeperiod;version=snapshot,\
Expand All @@ -204,7 +205,6 @@
io.openems.edge.controller.pvinverter.selltogridlimit;version=snapshot,\
io.openems.edge.controller.symmetric.balancing;version=snapshot,\
io.openems.edge.controller.symmetric.balancingschedule;version=snapshot,\
io.openems.edge.controller.symmetric.fixactivepower;version=snapshot,\
io.openems.edge.controller.symmetric.fixreactivepower;version=snapshot,\
io.openems.edge.controller.symmetric.limitactivepower;version=snapshot,\
io.openems.edge.controller.symmetric.linearpowerband;version=snapshot,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ActivePowerVoltageCharacteristicImpl extends AbstractOpenemsCompone
@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
private SymmetricMeter meter;

@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.OPTIONAL)
@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
private ManagedSymmetricEss ess;

@Reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>io.openems.edge.controller.symmetric.fixactivepower</name>
<name>io.openems.edge.controller.ess.fixactivepower</name>
<comment></comment>
<projects>
</projects>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePower.java=UTF-8
encoding//src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImpl.java=UTF-8
encoding/bnd.bnd=UTF-8
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.openems.edge.controller.symmetric.fixactivepower;
package io.openems.edge.controller.ess.fixactivepower;

import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@ObjectClassDefinition( //
name = "Controller Fix Active Power Symmetric", //
name = "Controller Ess Fix Active Power", //
description = "Defines a fixed charge/discharge power to a symmetric energy storage system.")
@interface Config {

Expand All @@ -17,11 +17,17 @@
@AttributeDefinition(name = "Is enabled?", description = "Is this Component enabled?")
boolean enabled() default true;

@AttributeDefinition(name = "Mode", description = "Set the type of mode.")
Mode mode() default Mode.MANUAL_ON;

@AttributeDefinition(name = "Ess-ID", description = "ID of Ess device.")
String ess_id();

@AttributeDefinition(name = "Charge/Discharge power [W]", description = "Negative values for Charge; positive for Discharge")
int power();

String webconsole_configurationFactory_nameHint() default "Controller Fix Active Power Symmetric [{id}]";
@AttributeDefinition(name = "Ess target filter", description = "This is auto-generated by 'Ess-ID'.")
String ess_target() default "";

String webconsole_configurationFactory_nameHint() default "Controller Ess Fix Active Power [{id}]";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.openems.edge.controller.ess.fixactivepower;

import io.openems.edge.common.channel.Doc;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.controller.api.Controller;

public interface EssFixActivePower extends Controller, OpenemsComponent {

public enum ChannelId implements io.openems.edge.common.channel.ChannelId {
;
private final Doc doc;

private ChannelId(Doc doc) {
this.doc = doc;
}

@Override
public Doc doc() {
return this.doc;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.openems.edge.controller.ess.fixactivepower;

import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.osgi.service.metatype.annotations.Designate;

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.edge.common.component.AbstractOpenemsComponent;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.controller.api.Controller;
import io.openems.edge.ess.api.ManagedSymmetricEss;

@Designate(ocd = Config.class, factory = true)
@Component(//
name = "Controller.Ess.FixActivePower", //
immediate = true, //
configurationPolicy = ConfigurationPolicy.REQUIRE //
)
public class EssFixActivePowerImpl extends AbstractOpenemsComponent
implements EssFixActivePower, Controller, OpenemsComponent {

@Reference
private ConfigurationAdmin cm;

@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
private ManagedSymmetricEss ess;

private Config config;

public EssFixActivePowerImpl() {
super(//
OpenemsComponent.ChannelId.values(), //
Controller.ChannelId.values(), //
EssFixActivePower.ChannelId.values() //
);
}

@Activate
void activate(ComponentContext context, Config config) {
super.activate(context, config.id(), config.alias(), config.enabled());
this.config = config;

if (OpenemsComponent.updateReferenceFilter(this.cm, this.servicePid(), "ess", config.ess_id())) {
return;
}
}

@Deactivate
protected void deactivate() {
super.deactivate();
}

@Override
public void run() throws OpenemsNamedException {
switch (this.config.mode()) {
case MANUAL_ON:
// Apply Active-Power Set-Point
this.ess.setActivePowerEquals(this.config.power());
break;

case MANUAL_OFF:
// Do nothing
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.openems.edge.controller.ess.fixactivepower;

public enum Mode {
MANUAL_ON, MANUAL_OFF;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.openems.edge.controller.ess.fixactivepower;

import org.junit.Test;

import io.openems.common.exceptions.OpenemsException;
import io.openems.common.types.ChannelAddress;
import io.openems.edge.common.test.AbstractComponentTest.TestCase;
import io.openems.edge.common.test.DummyConfigurationAdmin;
import io.openems.edge.controller.test.ControllerTest;
import io.openems.edge.ess.test.DummyManagedAsymmetricEss;

public class EssFixActivePowerImplTest {

private static final String CTRL_ID = "ctrl0";

private static final String ESS_ID = "ess0";

private static final ChannelAddress ESS_SET_ACTIVE_POWER_EQUALS = new ChannelAddress(ESS_ID,
"SetActivePowerEquals");

@Test
public void testOn() throws OpenemsException, Exception {
new ControllerTest(new EssFixActivePowerImpl()) //
.addReference("cm", new DummyConfigurationAdmin()) //
.addReference("ess", new DummyManagedAsymmetricEss(ESS_ID)) //
.activate(MyConfig.create() //
.setId(CTRL_ID) //
.setEssId(ESS_ID) //
.setMode(Mode.MANUAL_ON) //
.setPower(1234) //
.build()) //
.next(new TestCase() //
.output(ESS_SET_ACTIVE_POWER_EQUALS, 1234));
}

@Test
public void testOff() throws OpenemsException, Exception {
new ControllerTest(new EssFixActivePowerImpl()) //
.addReference("cm", new DummyConfigurationAdmin()) //
.addReference("ess", new DummyManagedAsymmetricEss(ESS_ID)) //
.activate(MyConfig.create() //
.setId(CTRL_ID) //
.setEssId(ESS_ID) //
.setMode(Mode.MANUAL_OFF) //
.setPower(1234) //
.build()) //
.next(new TestCase() //
.output(ESS_SET_ACTIVE_POWER_EQUALS, null));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.openems.edge.controller.ess.fixactivepower;

import io.openems.common.utils.ConfigUtils;
import io.openems.edge.common.test.AbstractComponentConfig;

@SuppressWarnings("all")
public class MyConfig extends AbstractComponentConfig implements Config {

protected static class Builder {
private String id = null;
private String essId = null;
public int power;
public Mode mode;

private Builder() {
}

public Builder setId(String id) {
this.id = id;
return this;
}

public Builder setEssId(String essId) {
this.essId = essId;
return this;
}

public Builder setPower(int power) {
this.power = power;
return this;
}

public Builder setMode(Mode mode) {
this.mode = mode;
return this;
}

public MyConfig build() {
return new MyConfig(this);
}
}

/**
* Create a Config builder.
*
* @return a {@link Builder}
*/
public static Builder create() {
return new Builder();
}

private final Builder builder;

private MyConfig(Builder builder) {
super(Config.class, builder.id);
this.builder = builder;
}

@Override
public String ess_id() {
return this.builder.essId;
}

@Override
public String ess_target() {
return ConfigUtils.generateReferenceTargetFilter(this.id(), this.ess_id());
}

@Override
public int power() {
return this.builder.power;
}

@Override
public Mode mode() {
return this.builder.mode;
}

}

This file was deleted.

Loading