Search in sources :

Example 1 with VirtualGateway

use of org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualGateway 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);
                }
            }
        });
    }
}
Also used : VirtualGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualGateway) DelayedExecuterCallback(org.eclipse.smarthome.binding.homematic.internal.misc.DelayedExecuter.DelayedExecuterCallback) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) ReloadFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadFromGatewayVirtualDatapointHandler) RssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.RssiVirtualDatapointHandler) ReloadAllFromGatewayVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadAllFromGatewayVirtualDatapointHandler) StateContactVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.StateContactVirtualDatapointHandler) SignalStrengthVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.SignalStrengthVirtualDatapointHandler) ButtonVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler) FirmwareVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.FirmwareVirtualDatapointHandler) ReloadRssiVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadRssiVirtualDatapointHandler) DeleteDeviceModeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler) VirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler) DeleteDeviceVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler) HmwIoModuleVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.HmwIoModuleVirtualDatapointHandler) OnTimeAutomaticVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.OnTimeAutomaticVirtualDatapointHandler) BatteryTypeVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler) DisplayOptionsVirtualDatapointHandler(org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayOptionsVirtualDatapointHandler)

Aggregations

BatteryTypeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler)1 ButtonVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler)1 DeleteDeviceModeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler)1 DeleteDeviceVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler)1 DisplayOptionsVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayOptionsVirtualDatapointHandler)1 FirmwareVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.FirmwareVirtualDatapointHandler)1 HmwIoModuleVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.HmwIoModuleVirtualDatapointHandler)1 OnTimeAutomaticVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.OnTimeAutomaticVirtualDatapointHandler)1 ReloadAllFromGatewayVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadAllFromGatewayVirtualDatapointHandler)1 ReloadFromGatewayVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadFromGatewayVirtualDatapointHandler)1 ReloadRssiVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ReloadRssiVirtualDatapointHandler)1 RssiVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.RssiVirtualDatapointHandler)1 SignalStrengthVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.SignalStrengthVirtualDatapointHandler)1 StateContactVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.StateContactVirtualDatapointHandler)1 VirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualDatapointHandler)1 VirtualGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.VirtualGateway)1 DelayedExecuterCallback (org.eclipse.smarthome.binding.homematic.internal.misc.DelayedExecuter.DelayedExecuterCallback)1 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)1