Search in sources :

Example 1 with VirtualDatapointHandler

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);
                }
            }
        });
    }
}
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)

Example 2 with VirtualDatapointHandler

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);
        }
    }
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) HmInterface(org.eclipse.smarthome.binding.homematic.internal.model.HmInterface) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) 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)

Example 3 with VirtualDatapointHandler

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);
            }
        }
    }
}
Also used : HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) 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) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Aggregations

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