use of org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock in project openhab-addons by openhab.
the class DataBlockTest method testValidPowerBlock.
@Test
public void testValidPowerBlock() {
Optional<Data> dataOpt = mc.parse(DataType.POWER);
assertTrue(dataOpt.isPresent());
PowerBlock b = (PowerBlock) dataOpt.get();
assertEquals("242 W", b.pvPowerSupply.toString(), "PV Supply");
assertEquals("14 W", b.gridPowerSupply.toString(), "Grid Supply");
assertEquals("0 W", b.gridPowerConsumpition.toString(), "Grid Consumption");
assertEquals("303 W", b.batteryPowerSupply.toString(), "Battery Supply");
}
use of org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock in project openhab-addons by openhab.
the class Parser method parse.
public Optional<Data> parse(DataType type) {
synchronized (bArray) {
if (type.equals(DataType.INFO) && callbackType.equals(DataType.INFO)) {
return Optional.of(new InfoBlock(Arrays.copyOfRange(bArray, INFO_REG_START, INFO_REG_SIZE * 2)));
} else if (type.equals(DataType.POWER) && callbackType.equals(DataType.DATA)) {
int start = (POWER_REG_START - INFO_REG_SIZE) * 2;
int end = start + POWER_REG_SIZE * 2;
return Optional.of(new PowerBlock(Arrays.copyOfRange(bArray, start, end)));
} else if (type.equals(DataType.EMERGENCY) && callbackType.equals(DataType.DATA)) {
int start = (EMS_REG_START - INFO_REG_SIZE) * 2;
int end = start + EMS_REG_SIZE * 2;
return Optional.of(new EmergencyBlock(Arrays.copyOfRange(bArray, start, end)));
} else if (type.equals(DataType.WALLBOX) && callbackType.equals(DataType.DATA)) {
int start = (WALLBOX_REG_START - INFO_REG_SIZE) * 2;
int end = start + WALLBOX_REG_SIZE * 2;
return Optional.of(new WallboxArray(Arrays.copyOfRange(bArray, start, end)));
} else if (type.equals(DataType.STRINGS) && callbackType.equals(DataType.DATA)) {
int start = (STRINGS_REG_START - INFO_REG_SIZE) * 2;
int end = start + STRINGS_REG_SIZE * 2;
return Optional.of(new StringBlock(Arrays.copyOfRange(bArray, start, end)));
}
}
logger.warn("Wrong Block requested. Request is {} but type is {}", type, callbackType);
return Optional.empty();
}
use of org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock in project openhab-addons by openhab.
the class DataBlockTest method testValidPowerBlockNegativePVSupply.
@Test
public void testValidPowerBlockNegativePVSupply() {
Optional<Data> dataOpt = mcNegativePVSupply.parse(DataType.POWER);
assertTrue(dataOpt.isPresent());
PowerBlock b = (PowerBlock) dataOpt.get();
assertEquals("-330 W", b.pvPowerSupply.toString(), "PV Supply");
assertEquals("14 W", b.gridPowerSupply.toString(), "Grid Supply");
assertEquals("0 W", b.gridPowerConsumpition.toString(), "Grid Consumption");
assertEquals("303 W", b.batteryPowerSupply.toString(), "Battery Supply");
}
Aggregations