use of org.eclipse.smarthome.binding.homematic.internal.misc.DelayedExecuter.DelayedExecuterCallback in project smarthome by eclipse.
the class AbstractHomematicGateway method sendDatapoint.
/**
* Main method for sending datapoints to the gateway. It handles scripts, variables, virtual datapoints, delayed
* executions and auto disabling.
*/
private void sendDatapoint(final HmDatapoint dp, final HmDatapointConfig dpConfig, final Object newValue, final String rxMode, final boolean ignoreVirtualDatapoints) throws IOException, HomematicClientException {
final HmDatapointInfo dpInfo = new HmDatapointInfo(dp);
if (dp.isPressDatapoint() || (config.getGatewayInfo().isHomegear() && dp.isVariable())) {
echoEvents.add(dpInfo);
}
if (dp.isReadOnly()) {
logger.warn("Datapoint is readOnly, it is not published to the gateway with id '{}': '{}'", id, dpInfo);
} else if (HmValueType.ACTION == dp.getType() && MiscUtils.isFalseValue(newValue)) {
logger.warn("Datapoint of type ACTION cannot be set to false, it is not published to the gateway with id '{}': '{}'", id, dpInfo);
} else {
final VirtualGateway gateway = this;
sendDelayedExecutor.start(dpInfo, dpConfig.getDelay(), new DelayedExecuterCallback() {
@Override
public void execute() throws IOException, HomematicClientException {
VirtualDatapointHandler virtualDatapointHandler = ignoreVirtualDatapoints ? null : getVirtualDatapointHandler(dp, newValue);
if (virtualDatapointHandler != null) {
logger.debug("Handling virtual datapoint '{}' on gateway with id '{}'", dp.getName(), id);
virtualDatapointHandler.handleCommand(gateway, dp, dpConfig, newValue);
} else if (dp.isScript()) {
if (MiscUtils.isTrueValue(newValue)) {
logger.debug("Executing script '{}' on gateway with id '{}'", dp.getInfo(), id);
executeScript(dp);
}
} else if (dp.isVariable()) {
logger.debug("Sending variable '{}' with value '{}' to gateway with id '{}'", dp.getInfo(), newValue, id);
setVariable(dp, newValue);
} else {
logger.debug("Sending datapoint '{}' with value '{}' to gateway with id '{}' using rxMode '{}'", dpInfo, newValue, id, rxMode == null ? "DEFAULT" : rxMode);
getRpcClient(dp.getChannel().getDevice().getHmInterface()).setDatapointValue(dp, newValue, rxMode);
}
dp.setValue(newValue);
if (MiscUtils.isTrueValue(newValue) && (dp.isPressDatapoint() || dp.isScript() || dp.isActionType())) {
disableDatapoint(dp, DEFAULT_DISABLE_DELAY);
}
}
});
}
}
use of org.eclipse.smarthome.binding.homematic.internal.misc.DelayedExecuter.DelayedExecuterCallback in project smarthome by eclipse.
the class AbstractHomematicGateway method disableDatapoint.
@Override
public void disableDatapoint(final HmDatapoint dp, double delay) {
try {
sendDelayedExecutor.start(new HmDatapointInfo(dp), delay, new DelayedExecuterCallback() {
@Override
public void execute() throws IOException {
if (MiscUtils.isTrueValue(dp.getValue())) {
dp.setValue(Boolean.FALSE);
gatewayAdapter.onStateUpdated(dp);
handleVirtualDatapointEvent(dp, true);
} else if (dp.getType() == HmValueType.ENUM && dp.getValue() != null && !dp.getValue().equals(0)) {
dp.setValue(dp.getMinValue());
gatewayAdapter.onStateUpdated(dp);
handleVirtualDatapointEvent(dp, true);
}
}
});
} catch (IOException | HomematicClientException ex) {
logger.error("{}", ex.getMessage(), ex);
}
}
Aggregations