use of org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray in project openhab-addons by openhab.
the class E3DCWallboxThingHandler method handle.
public void handle(AsyncModbusReadResult result) {
if (dataRead != ReadWriteSuccess.SUCCESS) {
dataRead = ReadWriteSuccess.SUCCESS;
updateStatus();
}
dataParser.handle(result);
Optional<Data> wbArrayOpt = dataParser.parse(DataType.WALLBOX);
if (wbArrayOpt.isPresent()) {
WallboxArray wbArray = (WallboxArray) wbArrayOpt.get();
OptionalInt wallboxId = getWallboxId(config);
if (wallboxId.isPresent()) {
Optional<WallboxBlock> blockOpt = wbArray.getWallboxBlock(wallboxId.getAsInt());
if (blockOpt.isPresent()) {
WallboxBlock block = blockOpt.get();
synchronized (this) {
currentBitSet = block.getBitSet();
}
updateState(wbAvailableChannel, block.wbAvailable);
updateState(wbSunmodeChannel, block.wbSunmode);
updateState(wbChargingAbortedChannel, block.wbChargingAborted);
updateState(wbChargingChannel, block.wbCharging);
updateState(wbJackLockedChannel, block.wbJackLocked);
updateState(wbJackPluggedChannel, block.wbJackPlugged);
updateState(wbSchukoOnChannel, block.wbSchukoOn);
updateState(wbSchukoPluggedChannel, block.wbSchukoPlugged);
updateState(wbSchukoLockedChannel, block.wbSchukoLocked);
updateState(wbSchukoRelay16Channel, block.wbSchukoRelay16);
updateState(wbRelay16Channel, block.wbRelay16);
updateState(wbRelay32Channel, block.wbRelay32);
updateState(wb1phaseChannel, block.wb1phase);
} else {
logger.debug("Unable to get ID {} from WallboxArray", wallboxId);
}
} else {
logger.debug("Wallbox ID {} not valid", wallboxId);
}
} else {
logger.debug("Unable to get {} from Bridge", DataType.WALLBOX);
}
}
use of org.openhab.binding.modbus.e3dc.internal.dto.WallboxArray 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.WallboxArray in project openhab-addons by openhab.
the class DataBlockTest method testValidWallboxBlock.
@Test
public void testValidWallboxBlock() {
Optional<Data> wba = mc.parse(DataType.WALLBOX);
assertTrue(wba.isPresent());
WallboxArray a = (WallboxArray) wba.get();
assertNotNull(a);
Optional<WallboxBlock> o = a.getWallboxBlock(0);
WallboxBlock b = o.get();
assertNotNull(b);
assertEquals(OnOffType.ON, b.wbAvailable, "Wallbox available");
assertEquals(OnOffType.ON, b.wbSunmode, "Wallbox Sunmode");
assertEquals(OnOffType.OFF, b.wb1phase, "Wallbox 1phase");
assertEquals(OnOffType.OFF, b.wbCharging, "Wallbox charging");
}
Aggregations