use of org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler 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.communicator.virtual.VirtualDatapointHandler in project smarthome by eclipse.
the class AbstractHomematicGateway method setInstallMode.
@Override
public void setInstallMode(boolean enable, int seconds) throws IOException {
HmDevice gwExtrasHm = devices.get(HmDevice.ADDRESS_GATEWAY_EXTRAS);
if (gwExtrasHm != null) {
// since the homematic virtual device exist: try setting install mode via its dataPoints
HmDatapoint installModeDataPoint = null;
HmDatapoint installModeDurationDataPoint = null;
// collect virtual datapoints to be accessed
HmChannel hmChannel = gwExtrasHm.getChannel(HmChannel.CHANNEL_NUMBER_EXTRAS);
HmDatapointInfo installModeDurationDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE_DURATION);
if (enable) {
installModeDurationDataPoint = hmChannel.getDatapoint(installModeDurationDataPointInfo);
}
HmDatapointInfo installModeDataPointInfo = new HmDatapointInfo(HmParamsetType.VALUES, hmChannel, HomematicConstants.VIRTUAL_DATAPOINT_NAME_INSTALL_MODE);
installModeDataPoint = hmChannel.getDatapoint(installModeDataPointInfo);
// first set duration on the datapoint
if (installModeDurationDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDurationDataPoint, null);
handler.handleCommand(this, installModeDurationDataPoint, new HmDatapointConfig(), seconds);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDurationDataPoint);
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDurationDataPoint, ex);
}
}
// now that the duration is set, we can enable / disable
if (installModeDataPoint != null) {
try {
VirtualDatapointHandler handler = getVirtualDatapointHandler(installModeDataPoint, null);
handler.handleCommand(this, installModeDataPoint, new HmDatapointConfig(), enable);
// notify thing if exists
gatewayAdapter.onStateUpdated(installModeDataPoint);
return;
} catch (HomematicClientException ex) {
logger.warn("Failed to send datapoint {}", installModeDataPoint, ex);
}
}
}
// no gwExtrasHm available (or previous approach failed), therefore use rpc client directly
for (HmInterface hmInterface : availableInterfaces.keySet()) {
if (hmInterface == HmInterface.RF || hmInterface == HmInterface.CUXD) {
getRpcClient(hmInterface).setInstallMode(hmInterface, enable, seconds);
}
}
}
use of org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler in project smarthome by eclipse.
the class AbstractHomematicGateway method prepareDevice.
/**
* Adds virtual datapoints to the device.
*/
private void prepareDevice(HmDevice device) {
for (VirtualDatapointHandler vdph : virtualDatapointHandlers) {
vdph.initialize(device);
}
devices.put(device.getAddress(), device);
logger.debug("Loaded device '{}' ({}) with {} datapoints", device.getAddress(), device.getType(), device.getDatapointCount());
if (logger.isTraceEnabled()) {
logger.trace("{}", device);
for (HmChannel channel : device.getChannels()) {
logger.trace(" {}", channel);
for (HmDatapoint dp : channel.getDatapoints()) {
logger.trace(" {}", dp);
}
}
}
}
Aggregations