Search in sources :

Example 1 with PowerBlock

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");
}
Also used : PowerBlock(org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Test(org.junit.jupiter.api.Test)

Example 2 with PowerBlock

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();
}
Also used : InfoBlock(org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock) PowerBlock(org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock) EmergencyBlock(org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock) StringBlock(org.openhab.binding.modbus.e3dc.internal.dto.StringBlock) WallboxArray(org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray)

Example 3 with PowerBlock

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");
}
Also used : PowerBlock(org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Test(org.junit.jupiter.api.Test)

Aggregations

PowerBlock (org.openhab.binding.modbus.e3dc.internal.dto.PowerBlock)3 Test (org.junit.jupiter.api.Test)2 Data (org.openhab.binding.modbus.e3dc.internal.modbus.Data)2 EmergencyBlock (org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock)1 InfoBlock (org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock)1 StringBlock (org.openhab.binding.modbus.e3dc.internal.dto.StringBlock)1 WallboxArray (org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray)1