use of org.openhab.core.io.transport.modbus.PollTask in project openhab-addons by openhab.
the class ModbusPollerThingHandler method unregisterPollTask.
/**
* Unregister poll task.
*
* No-op in case no poll task is registered, or if the initialization is incomplete.
*/
public synchronized void unregisterPollTask() {
logger.trace("unregisterPollTask()");
if (config == null) {
return;
}
PollTask localPollTask = this.pollTask;
if (localPollTask != null) {
logger.debug("Unregistering polling from ModbusManager");
comms.unregisterRegularPoll(localPollTask);
}
this.pollTask = null;
request = null;
comms = null;
updateStatus(ThingStatus.OFFLINE);
}
use of org.openhab.core.io.transport.modbus.PollTask in project openhab-addons by openhab.
the class AbstractSunSpecHandler method unregisterPollTask.
/**
* Unregister poll task.
*
* No-op in case no poll task is registered, or if the initialization is incomplete.
*/
private synchronized void unregisterPollTask() {
@Nullable PollTask task = pollTask;
if (task == null) {
return;
}
logger.debug("Unregistering polling from ModbusManager");
@Nullable ModbusCommunicationInterface mycomms = comms;
if (mycomms != null) {
mycomms.unregisterRegularPoll(task);
}
pollTask = null;
}
use of org.openhab.core.io.transport.modbus.PollTask in project openhab-addons by openhab.
the class BaseModbusThingHandler method registerRegularPoll.
/**
* Register regularly polled task. The method returns immediately, and the execution of the poll task will happen in
* the background.
*
* One can register only one regular poll task for triplet of (endpoint, request, callback).
*
* @param request request to send
* @param pollPeriodMillis poll interval, in milliseconds
* @param initialDelayMillis initial delay before starting polling, in milliseconds
* @param callback callback to call with data
* @param callback callback to call in case of failure
* @return poll task representing the regular poll
* @throws IllegalStateException when this communication has been closed already
*/
public PollTask registerRegularPoll(ModbusReadRequestBlueprint request, long pollPeriodMillis, long initialDelayMillis, ModbusReadCallback resultCallback, ModbusFailureCallback<ModbusReadRequestBlueprint> failureCallback) {
PollTask task = getModbus().registerRegularPoll(request, pollPeriodMillis, initialDelayMillis, resultCallback, failureCallback);
periodicPollers.add(task);
return task;
}
use of org.openhab.core.io.transport.modbus.PollTask in project openhab-addons by openhab.
the class ModbusDataHandlerTest method testInitGeneric.
/**
* @param pollerFunctionCode poller function code. Use null if you want to have data thing direct child of endpoint
* thing
* @param pollerStart start index of poller
* @param config thing config
* @param statusConsumer assertion method for data thingstatus
*/
private void testInitGeneric(ModbusReadFunctionCode pollerFunctionCode, int pollerStart, Configuration config, Consumer<ThingStatusInfo> statusConsumer) {
int pollLength = 3;
Bridge parent;
if (pollerFunctionCode == null) {
parent = createTcpMock();
addThing(parent);
} else {
ModbusSlaveEndpoint endpoint = new ModbusTCPSlaveEndpoint("thisishost", 502, false);
// Minimally mocked request
ModbusReadRequestBlueprint request = Mockito.mock(ModbusReadRequestBlueprint.class);
doReturn(pollerStart).when(request).getReference();
doReturn(pollLength).when(request).getDataLength();
doReturn(pollerFunctionCode).when(request).getFunctionCode();
PollTask task = Mockito.mock(PollTask.class);
doReturn(endpoint).when(task).getEndpoint();
doReturn(request).when(task).getRequest();
parent = createPollerMock("poller1", task);
}
String thingId = "read1";
ModbusDataThingHandler dataHandler = createDataHandler(thingId, parent, builder -> builder.withConfiguration(config), bundleContext);
statusConsumer.accept(dataHandler.getThing().getStatusInfo());
}
use of org.openhab.core.io.transport.modbus.PollTask in project openhab-addons by openhab.
the class ModbusDataHandlerTest method testValueTypeGeneric.
private void testValueTypeGeneric(ModbusReadFunctionCode functionCode, ValueType valueType, ThingStatus expectedStatus) {
ModbusSlaveEndpoint endpoint = new ModbusTCPSlaveEndpoint("thisishost", 502, false);
// Minimally mocked request
ModbusReadRequestBlueprint request = Mockito.mock(ModbusReadRequestBlueprint.class);
doReturn(3).when(request).getDataLength();
doReturn(functionCode).when(request).getFunctionCode();
PollTask task = Mockito.mock(PollTask.class);
doReturn(endpoint).when(task).getEndpoint();
doReturn(request).when(task).getRequest();
Bridge poller = createPollerMock("poller1", task);
Configuration dataConfig = new Configuration();
dataConfig.put("readStart", "1");
dataConfig.put("readTransform", "default");
dataConfig.put("readValueType", valueType.getConfigValue());
ModbusDataThingHandler dataHandler = createDataHandler("data1", poller, builder -> builder.withConfiguration(dataConfig));
assertThat(dataHandler.getThing().getStatus(), is(equalTo(expectedStatus)));
}
Aggregations