From 6023d3d17c8747d4acbf76239dc7e794cd92775d Mon Sep 17 00:00:00 2001 From: Stefan Feilmeier Date: Mon, 7 Dec 2020 15:17:07 +0100 Subject: [PATCH 1/2] Refactor Fix-Active-Power-Controller - Rename to namespace "io.openems.edge.controller.ess" - Add 'Mode' to be compatible with UI features - Use 'SetActivePowerEquals' Channel at ESS - Use @Reference to get the ESS - Add JUnit test --- io.openems.edge.application/EdgeApp.bndrun | 4 +- .../ActivePowerVoltageCharacteristicImpl.java | 2 +- .../.classpath | 0 .../.gitignore | 0 .../.project | 2 +- .../org.eclipse.core.resources.prefs | 4 + .../.settings/org.eclipse.jdt.core.prefs | 0 .../bnd.bnd | 0 .../readme.adoc | 0 .../ess}/fixactivepower/Config.java | 12 ++- .../ess/fixactivepower/EssFixActivePower.java | 23 ++++++ .../fixactivepower/EssFixActivePowerImpl.java | 74 +++++++++++++++++ .../controller/ess/fixactivepower/Mode.java | 5 ++ .../test/.gitignore | 0 .../EssFixActivePowerImplTest.java | 51 ++++++++++++ .../ess/fixactivepower/MyConfig.java | 79 ++++++++++++++++++ .../org.eclipse.core.resources.prefs | 3 - .../SymmetricFixActivePower.java | 80 ------------------- 18 files changed, 249 insertions(+), 90 deletions(-) rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/.classpath (100%) rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/.gitignore (100%) rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/.project (88%) create mode 100644 io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.core.resources.prefs rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/.settings/org.eclipse.jdt.core.prefs (100%) rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/bnd.bnd (100%) rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/readme.adoc (100%) rename {io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric => io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess}/fixactivepower/Config.java (71%) create mode 100644 io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePower.java create mode 100644 io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImpl.java create mode 100644 io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Mode.java rename {io.openems.edge.controller.symmetric.fixactivepower => io.openems.edge.controller.ess.fixactivepower}/test/.gitignore (100%) create mode 100644 io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImplTest.java create mode 100644 io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/MyConfig.java delete mode 100644 io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.core.resources.prefs delete mode 100644 io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/SymmetricFixActivePower.java diff --git a/io.openems.edge.application/EdgeApp.bndrun b/io.openems.edge.application/EdgeApp.bndrun index 4088c647588..88972b87f80 100644 --- a/io.openems.edge.application/EdgeApp.bndrun +++ b/io.openems.edge.application/EdgeApp.bndrun @@ -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',\ @@ -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',\ @@ -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,\ @@ -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,\ diff --git a/io.openems.edge.controller.ess.activepowervoltagecharacteristic/src/io/openems/edge/controller/ess/activepowervoltagecharacteristic/ActivePowerVoltageCharacteristicImpl.java b/io.openems.edge.controller.ess.activepowervoltagecharacteristic/src/io/openems/edge/controller/ess/activepowervoltagecharacteristic/ActivePowerVoltageCharacteristicImpl.java index 2f514c01d8e..ac4a9b0fdff 100644 --- a/io.openems.edge.controller.ess.activepowervoltagecharacteristic/src/io/openems/edge/controller/ess/activepowervoltagecharacteristic/ActivePowerVoltageCharacteristicImpl.java +++ b/io.openems.edge.controller.ess.activepowervoltagecharacteristic/src/io/openems/edge/controller/ess/activepowervoltagecharacteristic/ActivePowerVoltageCharacteristicImpl.java @@ -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 diff --git a/io.openems.edge.controller.symmetric.fixactivepower/.classpath b/io.openems.edge.controller.ess.fixactivepower/.classpath similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/.classpath rename to io.openems.edge.controller.ess.fixactivepower/.classpath diff --git a/io.openems.edge.controller.symmetric.fixactivepower/.gitignore b/io.openems.edge.controller.ess.fixactivepower/.gitignore similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/.gitignore rename to io.openems.edge.controller.ess.fixactivepower/.gitignore diff --git a/io.openems.edge.controller.symmetric.fixactivepower/.project b/io.openems.edge.controller.ess.fixactivepower/.project similarity index 88% rename from io.openems.edge.controller.symmetric.fixactivepower/.project rename to io.openems.edge.controller.ess.fixactivepower/.project index 8fbdd6db51c..fa4276b4229 100644 --- a/io.openems.edge.controller.symmetric.fixactivepower/.project +++ b/io.openems.edge.controller.ess.fixactivepower/.project @@ -1,6 +1,6 @@ - io.openems.edge.controller.symmetric.fixactivepower + io.openems.edge.controller.ess.fixactivepower diff --git a/io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.core.resources.prefs b/io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..e5895520639 --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.core.resources.prefs @@ -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 diff --git a/io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.jdt.core.prefs b/io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.jdt.core.prefs rename to io.openems.edge.controller.ess.fixactivepower/.settings/org.eclipse.jdt.core.prefs diff --git a/io.openems.edge.controller.symmetric.fixactivepower/bnd.bnd b/io.openems.edge.controller.ess.fixactivepower/bnd.bnd similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/bnd.bnd rename to io.openems.edge.controller.ess.fixactivepower/bnd.bnd diff --git a/io.openems.edge.controller.symmetric.fixactivepower/readme.adoc b/io.openems.edge.controller.ess.fixactivepower/readme.adoc similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/readme.adoc rename to io.openems.edge.controller.ess.fixactivepower/readme.adoc diff --git a/io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/Config.java b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Config.java similarity index 71% rename from io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/Config.java rename to io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Config.java index d7767382c3f..7c6df0ee919 100644 --- a/io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/Config.java +++ b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Config.java @@ -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 { @@ -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}]"; } \ No newline at end of file diff --git a/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePower.java b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePower.java new file mode 100644 index 00000000000..39104aa65cb --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePower.java @@ -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; + } + } + +} diff --git a/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImpl.java b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImpl.java new file mode 100644 index 00000000000..402aeaaf672 --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImpl.java @@ -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; + } + } +} diff --git a/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Mode.java b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Mode.java new file mode 100644 index 00000000000..a20ad50e837 --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/src/io/openems/edge/controller/ess/fixactivepower/Mode.java @@ -0,0 +1,5 @@ +package io.openems.edge.controller.ess.fixactivepower; + +public enum Mode { + MANUAL_ON, MANUAL_OFF; +} diff --git a/io.openems.edge.controller.symmetric.fixactivepower/test/.gitignore b/io.openems.edge.controller.ess.fixactivepower/test/.gitignore similarity index 100% rename from io.openems.edge.controller.symmetric.fixactivepower/test/.gitignore rename to io.openems.edge.controller.ess.fixactivepower/test/.gitignore diff --git a/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImplTest.java b/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImplTest.java new file mode 100644 index 00000000000..b535173e95f --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/EssFixActivePowerImplTest.java @@ -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)); + } + +} diff --git a/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/MyConfig.java b/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/MyConfig.java new file mode 100644 index 00000000000..f913eafbd61 --- /dev/null +++ b/io.openems.edge.controller.ess.fixactivepower/test/io/openems/edge/controller/ess/fixactivepower/MyConfig.java @@ -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; + } + +} \ No newline at end of file diff --git a/io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.core.resources.prefs b/io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 64006d8f7ee..00000000000 --- a/io.openems.edge.controller.symmetric.fixactivepower/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/io/openems/edge/controller/symmetric/fixactivepower/SymmetricFixActivePower.java=UTF-8 -encoding/bnd.bnd=UTF-8 diff --git a/io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/SymmetricFixActivePower.java b/io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/SymmetricFixActivePower.java deleted file mode 100644 index 7f1870cdafc..00000000000 --- a/io.openems.edge.controller.symmetric.fixactivepower/src/io/openems/edge/controller/symmetric/fixactivepower/SymmetricFixActivePower.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.openems.edge.controller.symmetric.fixactivepower; - -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.metatype.annotations.Designate; - -import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; -import io.openems.edge.common.channel.Doc; -import io.openems.edge.common.component.AbstractOpenemsComponent; -import io.openems.edge.common.component.ComponentManager; -import io.openems.edge.common.component.OpenemsComponent; -import io.openems.edge.controller.api.Controller; -import io.openems.edge.ess.api.ManagedSymmetricEss; -import io.openems.edge.ess.power.api.Phase; -import io.openems.edge.ess.power.api.Pwr; -import io.openems.edge.ess.power.api.Relationship; - -@Designate(ocd = Config.class, factory = true) -@Component(name = "Controller.Symmetric.FixActivePower", immediate = true, configurationPolicy = ConfigurationPolicy.REQUIRE) -public class SymmetricFixActivePower extends AbstractOpenemsComponent implements Controller, OpenemsComponent { - - // private final Logger log = - // LoggerFactory.getLogger(SymmetricFixActivePower.class); - - @Reference - protected ComponentManager componentManager; - - private Config config; - - 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; - } - } - - public SymmetricFixActivePower() { - super(// - OpenemsComponent.ChannelId.values(), // - Controller.ChannelId.values(), // - ChannelId.values() // - ); - } - - @Activate - void activate(ComponentContext context, Config config) { - super.activate(context, config.id(), config.alias(), config.enabled()); - this.config = config; - } - - @Deactivate - protected void deactivate() { - super.deactivate(); - } - - @Override - public void run() throws OpenemsNamedException { - ManagedSymmetricEss ess = this.componentManager.getComponent(this.config.ess_id()); - - // adjust value so that it fits into Min/MaxActivePower - int calculatedPower = ess.getPower().fitValueIntoMinMaxPower(this.id(), ess, Phase.ALL, Pwr.ACTIVE, this.config.power()); - - /* - * set result - */ - ess.addPowerConstraintAndValidate("SymmetricFixActivePower", Phase.ALL, Pwr.ACTIVE, Relationship.EQUALS, - calculatedPower); - } -} From 461f4de9b09b56765323e1cb33b6fb9300f66f74 Mon Sep 17 00:00:00 2001 From: Fabian Schwarzbeck Date: Tue, 8 Dec 2020 23:25:31 +0100 Subject: [PATCH 2/2] add UI widget --- .../fixactivepower.component.html | 42 +++++++ .../fixactivepower.component.ts | 45 ++++++++ .../fixactivepower/modal/modal.component.html | 104 ++++++++++++++++++ .../fixactivepower/modal/modal.component.ts | 83 ++++++++++++++ ui/src/app/edge/live/live.component.html | 4 + ui/src/app/edge/live/live.module.ts | 5 + ui/src/app/shared/type/widget.ts | 1 + 7 files changed, 284 insertions(+) create mode 100644 ui/src/app/edge/live/fixactivepower/fixactivepower.component.html create mode 100644 ui/src/app/edge/live/fixactivepower/fixactivepower.component.ts create mode 100644 ui/src/app/edge/live/fixactivepower/modal/modal.component.html create mode 100644 ui/src/app/edge/live/fixactivepower/modal/modal.component.ts diff --git a/ui/src/app/edge/live/fixactivepower/fixactivepower.component.html b/ui/src/app/edge/live/fixactivepower/fixactivepower.component.html new file mode 100644 index 00000000000..7fea3b66b84 --- /dev/null +++ b/ui/src/app/edge/live/fixactivepower/fixactivepower.component.html @@ -0,0 +1,42 @@ + + + + FixActivePower + + + + + + + + + + + + + + + +
+ General.state + + + General.on + + + General.off + + +
+ General.dischargePower + + {{ component.properties.power | unitvalue:'kW' }} +
+ General.chargePower + + {{ (component.properties.power) * -1 | unitvalue:'kW' }} +
+
+
\ No newline at end of file diff --git a/ui/src/app/edge/live/fixactivepower/fixactivepower.component.ts b/ui/src/app/edge/live/fixactivepower/fixactivepower.component.ts new file mode 100644 index 00000000000..1b24649aa63 --- /dev/null +++ b/ui/src/app/edge/live/fixactivepower/fixactivepower.component.ts @@ -0,0 +1,45 @@ +import { ActivatedRoute } from '@angular/router'; +import { FixActivePowerModalComponent } from './modal/modal.component'; +import { Component, Input } from '@angular/core'; +import { Edge, EdgeConfig, Service } from '../../../shared/shared'; +import { ModalController } from '@ionic/angular'; + +@Component({ + selector: FixActivePowerComponent.SELECTOR, + templateUrl: './fixactivepower.component.html' +}) +export class FixActivePowerComponent { + + @Input() private componentId: string | null = null; + + private static readonly SELECTOR = "fixactivepower"; + + private edge: Edge = null; + public component: EdgeConfig.Component | null = null; + + constructor( + private route: ActivatedRoute, + public modalCtrl: ModalController, + public service: Service, + ) { } + + ngOnInit() { + this.service.setCurrentComponent('', this.route).then(edge => { + this.edge = edge; + this.service.getConfig().then(config => { + this.component = config.getComponent(this.componentId); + }) + }) + } + + async presentModal() { + const modal = await this.modalCtrl.create({ + component: FixActivePowerModalComponent, + componentProps: { + component: this.component, + edge: this.edge, + } + }); + return await modal.present(); + } +} diff --git a/ui/src/app/edge/live/fixactivepower/modal/modal.component.html b/ui/src/app/edge/live/fixactivepower/modal/modal.component.html new file mode 100644 index 00000000000..891d3314db4 --- /dev/null +++ b/ui/src/app/edge/live/fixactivepower/modal/modal.component.html @@ -0,0 +1,104 @@ + + + FixActivePower + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ General.state + + + General.on + + + General.off + + +
+ General.dischargePower + + {{ component.properties.power | unitvalue:'W' }} +
+ General.chargePower + + {{ (component.properties.power) * -1 | unitvalue:'W' }} +
+
+ + + + + General.on + + + + + + General.off + + + + + + + + + + + +
+ General.power + + + + +  W + +
+
+ + + + Negative Leistung = Beladung + + + Positive Leistung = Entladung + + + + + + + + + +
+
+ + + +
\ No newline at end of file diff --git a/ui/src/app/edge/live/fixactivepower/modal/modal.component.ts b/ui/src/app/edge/live/fixactivepower/modal/modal.component.ts new file mode 100644 index 00000000000..c778d3da59e --- /dev/null +++ b/ui/src/app/edge/live/fixactivepower/modal/modal.component.ts @@ -0,0 +1,83 @@ +import { Component, Input } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; +import { ModalController } from '@ionic/angular'; +import { TranslateService } from '@ngx-translate/core'; +import { Edge, EdgeConfig, Service, Websocket } from '../../../../shared/shared'; + +@Component({ + selector: FixActivePowerModalComponent.SELECTOR, + templateUrl: './modal.component.html' +}) +export class FixActivePowerModalComponent { + + @Input() public edge: Edge | null = null; + @Input() public component: EdgeConfig.Component | null = null; + + private static readonly SELECTOR = "fixactivepower-modal"; + + public formGroup: FormGroup; + public loading: boolean = false; + + constructor( + public modalCtrl: ModalController, + public service: Service, + public formBuilder: FormBuilder, + public websocket: Websocket, + public translate: TranslateService, + ) { } + + ngOnInit() { + this.formGroup = this.formBuilder.group({ + mode: new FormControl(this.component.properties.mode), + power: new FormControl(this.component.properties.power), + }) + } + + public updateControllerMode(event: CustomEvent) { + let oldMode = this.component.properties['mode']; + let newMode = event.detail.value; + + if (this.edge != null) { + this.edge.updateComponentConfig(this.websocket, this.component.id, [ + { name: 'mode', value: newMode } + ]).then(() => { + this.component.properties.mode = newMode; + this.formGroup.markAsPristine(); + this.service.toast(this.translate.instant('General.changeAccepted'), 'success'); + }).catch(reason => { + this.component.properties.mode = oldMode; + this.service.toast(this.translate.instant('General.changeFailed') + '\n' + reason.error.message, 'danger'); + console.warn(reason); + }); + } + } + + applyChanges() { + if (this.edge != null) { + if (this.edge.roleIsAtLeast('owner')) { + let updateComponentArray = []; + Object.keys(this.formGroup.controls).forEach((element, index) => { + if (this.formGroup.controls[element].dirty) { + updateComponentArray.push({ name: Object.keys(this.formGroup.controls)[index], value: this.formGroup.controls[element].value }) + } + }) + this.loading = true; + this.edge.updateComponentConfig(this.websocket, this.component.id, updateComponentArray).then(() => { + this.component.properties.mode = this.formGroup.controls['mode'].value; + this.component.properties.power = this.formGroup.controls['power'].value; + this.loading = false; + this.service.toast(this.translate.instant('General.changeAccepted'), 'success'); + }).catch(reason => { + this.formGroup.controls['mode'].setValue(this.component.properties.mode); + this.formGroup.controls['power'].setValue(this.component.properties.power); + this.loading = false; + this.service.toast(this.translate.instant('General.changeFailed') + '\n' + reason.error.message, 'danger'); + console.warn(reason); + }) + this.formGroup.markAsPristine() + } else { + this.service.toast(this.translate.instant('General.insufficientRights'), 'danger'); + } + } + } +} \ No newline at end of file diff --git a/ui/src/app/edge/live/live.component.html b/ui/src/app/edge/live/live.component.html index f104143920e..2246f36276c 100644 --- a/ui/src/app/edge/live/live.component.html +++ b/ui/src/app/edge/live/live.component.html @@ -110,6 +110,10 @@ class="ion-no-padding"> + + + +