use of org.openhab.core.io.transport.modbus.AsyncModbusWriteResult in project openhab-addons by openhab.
the class ModbusDataHandlerTest method testWriteHandlingGeneric.
@SuppressWarnings({ "null" })
private ModbusDataThingHandler testWriteHandlingGeneric(String start, String transform, ValueType valueType, String writeType, ModbusWriteFunctionCode successFC, String channel, Command command, Exception error, BundleContext context, boolean parentIsEndpoint) {
ModbusSlaveEndpoint endpoint = new ModbusTCPSlaveEndpoint("thisishost", 502, false);
// Minimally mocked request
ModbusReadRequestBlueprint request = Mockito.mock(ModbusReadRequestBlueprint.class);
PollTask task = Mockito.mock(PollTask.class);
doReturn(endpoint).when(task).getEndpoint();
doReturn(request).when(task).getRequest();
final Bridge parent;
if (parentIsEndpoint) {
parent = createTcpMock();
addThing(parent);
} else {
parent = createPollerMock("poller1", task);
}
Configuration dataConfig = new Configuration();
dataConfig.put("readStart", "");
dataConfig.put("writeStart", start);
dataConfig.put("writeTransform", transform);
dataConfig.put("writeValueType", valueType.getConfigValue());
dataConfig.put("writeType", writeType);
String thingId = "write";
ModbusDataThingHandler dataHandler = createDataHandler(thingId, parent, builder -> builder.withConfiguration(dataConfig), context);
assertThat(dataHandler.getThing().getStatus(), is(equalTo(ThingStatus.ONLINE)));
dataHandler.handleCommand(new ChannelUID(dataHandler.getThing().getUID(), channel), command);
if (error != null) {
dataHandler.handleReadError(new AsyncModbusFailure<ModbusReadRequestBlueprint>(request, error));
} else {
ModbusResponse resp = new ModbusResponse() {
@Override
public int getFunctionCode() {
return successFC.getFunctionCode();
}
};
dataHandler.onWriteResponse(new AsyncModbusWriteResult(Mockito.mock(ModbusWriteRequestBlueprint.class), resp));
}
return dataHandler;
}
use of org.openhab.core.io.transport.modbus.AsyncModbusWriteResult in project openhab-core by openhab.
the class ModbusManagerImpl method invokeCallbackWithResponse.
private void invokeCallbackWithResponse(ModbusWriteRequestBlueprint request, ModbusWriteCallback callback, org.openhab.core.io.transport.modbus.ModbusResponse response) {
try {
logger.trace("Calling write response callback {} for request {}. Response was {}", callback, request, response);
callback.handle(new AsyncModbusWriteResult(request, response));
} finally {
logger.trace("Called write response callback {} for request {}. Response was {}", callback, request, response);
}
}
Aggregations