Search in sources :

Example 1 with ConverterTypeException

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

Aggregations

IOException (java.io.IOException)1 HomematicGateway (org.eclipse.smarthome.binding.homematic.internal.communicator.HomematicGateway)1 ConverterException (org.eclipse.smarthome.binding.homematic.internal.converter.ConverterException)1 ConverterTypeException (org.eclipse.smarthome.binding.homematic.internal.converter.ConverterTypeException)1 HomematicClientException (org.eclipse.smarthome.binding.homematic.internal.misc.HomematicClientException)1 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)1 HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)1 HmDatapointConfig (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointConfig)1 HmDatapointInfo (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapointInfo)1 ConfigValidationException (org.eclipse.smarthome.config.core.validation.ConfigValidationException)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1