Skip to content

Commit

Permalink
Implement a Grid_Meter Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0w3y committed Apr 12, 2024
1 parent a041a91 commit 73092e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package io.openems.edge.deye.gridmeter;

import junit.framework.TestCase;
import org.junit.Test;

public class DeyeGridMeterImplTest extends TestCase {
import io.openems.edge.bridge.modbus.test.DummyModbusBridge;
import io.openems.edge.common.test.ComponentTest;
import io.openems.edge.common.test.DummyConfigurationAdmin;

public class DeyeGridMeterImplTest {

private static final String METER_ID = "meter0";
private static final String MODBUS_ID = "modbus0";

@Test
public void test() throws Exception {
new ComponentTest(new DeyeGridMeterImpl()) //
.addReference("cm", new DummyConfigurationAdmin()) //
.addReference("setModbus", new DummyModbusBridge(MODBUS_ID)) //
.activate(MyConfig.create() //
.setId(METER_ID) //
.setModbusId(MODBUS_ID) //
.build()) //
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import io.openems.common.test.AbstractComponentConfig;
import io.openems.common.utils.ConfigUtils;
import io.openems.edge.common.startstop.StartStopConfig;
import io.openems.edge.meter.api.MeterType;

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

protected static class Builder {
private String id = null;
private StartStopConfig startStopConfig = null;
private String modbusId = null;
private boolean activateWatchdog;
private String id;
private String modbusId;
private int modbusUnitId;

private Builder() {
}
Expand All @@ -21,21 +20,11 @@ public Builder setId(String id) {
return this;
}

public Builder setStartStopConfig(StartStopConfig startStopConfig) {
this.startStopConfig = startStopConfig;
return this;
}

public Builder setModbusId(String modbusId) {
this.modbusId = modbusId;
return this;
}

public Builder setActivateWatchdog(boolean activateWatchdog) {
this.activateWatchdog = activateWatchdog;
return this;
}

public MyConfig build() {
return new MyConfig(this);
}
Expand Down Expand Up @@ -63,13 +52,13 @@ public String modbus_id() {
}

@Override
public int modbusUnitId() {
return 0;
public String Modbus_target() {
return ConfigUtils.generateReferenceTargetFilter(this.id(), this.modbus_id());
}

@Override
public String Modbus_target() {
return ConfigUtils.generateReferenceTargetFilter(this.id(), this.modbus_id());
public int modbusUnitId() {
return this.builder.modbusUnitId;
}

}

0 comments on commit 73092e3

Please sign in to comment.