Search in sources :

Example 46 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class HomematicThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("Received command '{}' for channel '{}'", command, channelUID);
    HmDatapoint dp = null;
    try {
        HomematicGateway gateway = getHomematicGateway();
        HmDatapointInfo dpInfo = UidUtils.createHmDatapointInfo(channelUID);
        if (RefreshType.REFRESH == command) {
            logger.debug("Refreshing {}", dpInfo);
            dpInfo = new HmDatapointInfo(dpInfo.getAddress(), HmParamsetType.VALUES, 0, VIRTUAL_DATAPOINT_NAME_RELOAD_FROM_GATEWAY);
            dp = gateway.getDatapoint(dpInfo);
            sendDatapoint(dp, new HmDatapointConfig(), Boolean.TRUE);
        } else {
            Channel channel = getThing().getChannel(channelUID.getId());
            if (channel == null) {
                logger.warn("Channel '{}' not found in thing '{}' on gateway '{}'", channelUID, getThing().getUID(), gateway.getId());
            } else {
                if (StopMoveType.STOP == command && DATAPOINT_NAME_LEVEL.equals(dpInfo.getName())) {
                    // special case with stop type (rollershutter)
                    dpInfo.setName(DATAPOINT_NAME_STOP);
                    HmDatapoint stopDp = gateway.getDatapoint(dpInfo);
                    ChannelUID stopChannelUID = UidUtils.generateChannelUID(stopDp, getThing().getUID());
                    handleCommand(stopChannelUID, OnOffType.ON);
                } else {
                    dp = gateway.getDatapoint(dpInfo);
                    TypeConverter<?> converter = ConverterFactory.createConverter(channel.getAcceptedItemType());
                    Object newValue = converter.convertToBinding(command, dp);
                    HmDatapointConfig config = getChannelConfig(channel, dp);
                    sendDatapoint(dp, config, newValue);
                }
            }
        }
    } catch (HomematicClientException | GatewayNotAvailableException ex) {
        logger.warn("{}", ex.getMessage());
    } catch (IOException ex) {
        if (dp != null && dp.getChannel().getDevice().isOffline()) {
            logger.warn("Device '{}' is OFFLINE, can't send command '{}' for channel '{}'", dp.getChannel().getDevice().getAddress(), command, channelUID);
            logger.trace("{}", ex.getMessage(), ex);
        } else {
            logger.error("{}", ex.getMessage(), ex);
        }
    } catch (ConverterTypeException ex) {
        logger.warn("{}, please check the item type and the commands in your scripts", ex.getMessage());
    } catch (Exception ex) {
        logger.error("{}", ex.getMessage(), ex);
    }
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) ConverterException(org.eclipse.smarthome.binding.homematic.internal.converter.ConverterException) ConverterTypeException(org.eclipse.smarthome.binding.homematic.internal.converter.ConverterTypeException) ConfigValidationException(org.eclipse.smarthome.config.core.validation.ConfigValidationException) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) ConverterTypeException(org.eclipse.smarthome.binding.homematic.internal.converter.ConverterTypeException) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) HomematicGateway(org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway) HmDatapointInfo(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)

Example 47 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class AbstractHomematicGateway method loadChannelValues.

@Override
public void loadChannelValues(HmChannel channel) throws IOException {
    if (channel.getDevice().isGatewayExtras()) {
        if (channel.getNumber() != HmChannel.CHANNEL_NUMBER_EXTRAS) {
            List<HmDatapoint> datapoints = channel.getDatapoints();
            if (channel.getNumber() == HmChannel.CHANNEL_NUMBER_VARIABLE) {
                loadVariables(channel);
                logger.debug("Loaded {} gateway variable(s)", datapoints.size());
            } else if (channel.getNumber() == HmChannel.CHANNEL_NUMBER_SCRIPT) {
                loadScripts(channel);
                logger.debug("Loaded {} gateway script(s)", datapoints.size());
            }
        }
    } else {
        logger.debug("Loading values for channel {} of device '{}'", channel, channel.getDevice().getAddress());
        setChannelDatapointValues(channel, HmParamsetType.MASTER);
        setChannelDatapointValues(channel, HmParamsetType.VALUES);
    }
    for (HmDatapoint dp : channel.getDatapoints()) {
        handleVirtualDatapointEvent(dp, false);
    }
    channel.setInitialized(true);
}
Also used : HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 48 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint 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)

Example 49 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class AbstractHomematicGateway method eventReceived.

@Override
public void eventReceived(HmDatapointInfo dpInfo, Object newValue) {
    String className = newValue == null ? "Unknown" : newValue.getClass().getSimpleName();
    logger.debug("Received new ({}) value '{}' for '{}' from gateway with id '{}'", className, newValue, dpInfo, id);
    if (echoEvents.remove(dpInfo)) {
        logger.debug("Echo event detected, ignoring '{}'", dpInfo);
    } else {
        try {
            if (connectionTrackerThread != null && dpInfo.isPong() && id.equals(newValue)) {
                connectionTrackerThread.pongReceived();
            }
            if (initialized) {
                final HmDatapoint dp = getDatapoint(dpInfo);
                HmDatapointConfig config = gatewayAdapter.getDatapointConfig(dp);
                receiveDelayedExecutor.start(dpInfo, config.getReceiveDelay(), () -> {
                    dp.setValue(newValue);
                    gatewayAdapter.onStateUpdated(dp);
                    handleVirtualDatapointEvent(dp, true);
                    if (dp.isPressDatapoint() && MiscUtils.isTrueValue(dp.getValue())) {
                        disableDatapoint(dp, DEFAULT_DISABLE_DELAY);
                    }
                });
            }
        } catch (HomematicClientException | IOException ex) {
        // ignore
        }
    }
}
Also used : HmDatapointConfig(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig) HomematicClientException(org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException) IOException(java.io.IOException) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Example 50 with HmDatapoint

use of org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint in project smarthome by eclipse.

the class ButtonDatapointTest method createPressDatapoint.

private HmDatapoint createPressDatapoint(String channelName, Object value) {
    HmDatapoint pressDp = new HmDatapoint(channelName, "", HmValueType.ACTION, value, true, HmParamsetType.VALUES);
    HmChannel hmChannel = new HmChannel(channelName, 1);
    HmDevice device = new HmDevice("ABC12345", HmInterface.RF, "HM-MOCK", "mockid", "mockid", "mockfw");
    hmChannel.setDevice(device);
    device.addChannel(hmChannel);
    hmChannel.addDatapoint(pressDp);
    pressDp.setChannel(hmChannel);
    bvdpHandler.initialize(device);
    return pressDp;
}
Also used : HmDevice(org.eclipse.smarthome.binding.homematic.internal.model.HmDevice) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Aggregations

HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)55 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)21 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)12 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)7 HmDevice (org.eclipse.smarthome.binding.homematic.internal.model.HmDevice)7 Test (org.junit.Test)6 IOException (java.io.IOException)5 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)5 ArrayList (java.util.ArrayList)4 HomematicGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway)4 Channel (org.eclipse.smarthome.core.thing.Channel)4 JavaTest (org.eclipse.smarthome.test.java.JavaTest)4 Map (java.util.Map)3 TclScriptDataEntry (org.eclipse.smarthome.binding.homematic.internal.model.TclScriptDataEntry)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 HashMap (java.util.HashMap)2 BatteryTypeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.BatteryTypeVirtualDatapointHandler)2 ButtonVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.ButtonVirtualDatapointHandler)2 DeleteDeviceModeVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceModeVirtualDatapointHandler)2 DeleteDeviceVirtualDatapointHandler (org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DeleteDeviceVirtualDatapointHandler)2