Search in sources :

Example 1 with EmergencyBlock

use of org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock in project openhab-addons by openhab.

the class DataBlockTest method testValidEmergency.

@Test
public void testValidEmergency() {
    Optional<Data> dataOpt = mc.parse(DataType.EMERGENCY);
    assertTrue(dataOpt.isPresent());
    EmergencyBlock b = (EmergencyBlock) dataOpt.get();
    assertEquals(EmergencyBlock.EP_NOT_SUPPORTED, b.epStatus.toFullString(), "EMS Status");
    assertEquals(OnOffType.OFF, b.batteryChargingLocked, "Battery charging locked");
    assertEquals(OnOffType.OFF, b.batteryDischargingLocked, "Battery discharging locked");
    assertEquals(OnOffType.OFF, b.epPossible, "EP possible");
    assertEquals(OnOffType.OFF, b.weatherPredictedCharging, "Weather Predicted charging");
    assertEquals(OnOffType.OFF, b.regulationStatus, "Regulation Status");
    assertEquals(OnOffType.OFF, b.chargeLockTime, "Charge Lock Time");
    assertEquals(OnOffType.OFF, b.dischargeLockTime, "Discharge Lock Time");
}
Also used : EmergencyBlock(org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock) Data(org.openhab.binding.modbus.e3dc.internal.modbus.Data) Test(org.junit.jupiter.api.Test)

Example 2 with EmergencyBlock

use of org.openhab.binding.modbus.e3dc.internal.dto.EmergencyBlock 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)

Aggregations

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