Search in sources :

Example 1 with StopMoveType

use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.

the class UrtsiBinding method sendToUrtsi.

/**
     * The method determines the appropriate
     * {@link org.openhab.core.binding.BindingProvider} and uses it to get the
     * corresponding URTSI device and channel. Bases on the given type a command
     * is send to the device.
     *
     * @param itemName
     *            name of the item
     * @param type
     *            Type of the command or status update
     * @return Returns true, if the command has been executed successfully.
     *         Returns false otherwise.
     * @throws BindingConfigParseException
     */
private boolean sendToUrtsi(String itemName, Type type) {
    UrtsiBindingProvider provider = null;
    if (!providers.isEmpty()) {
        provider = providers.iterator().next();
    }
    if (provider == null) {
        logger.error("doesn't find matching binding provider [itemName={}, type={}]", itemName, type);
        return false;
    }
    String urtsiDeviceId = provider.getDeviceId(itemName);
    UrtsiDevice urtsiDevice = idToDeviceMap.get(urtsiDeviceId);
    if (urtsiDevice == null) {
        logger.error("No serial port has been configured for urtsi device id '{}'", urtsiDeviceId);
        return false;
    }
    int channel = provider.getChannel(itemName);
    int address = provider.getAddress(itemName);
    logger.debug("Send to URTSI for item: {}; Type: {}", itemName, type);
    String actionKey = null;
    if (type instanceof UpDownType) {
        switch((UpDownType) type) {
            case UP:
                actionKey = COMMAND_UP;
                break;
            case DOWN:
                actionKey = COMMAND_DOWN;
                break;
        }
    } else if (type instanceof StopMoveType) {
        switch((StopMoveType) type) {
            case STOP:
                actionKey = COMMAND_STOP;
                break;
            default:
                break;
        }
    }
    logger.debug("Action key: {}", actionKey);
    if (actionKey != null) {
        String channelString = String.format("%02d", channel);
        String addressString = String.format("%02d", address);
        String command = addressString + channelString + actionKey;
        boolean executedSuccessfully = urtsiDevice.writeString(command);
        if (!executedSuccessfully) {
            logger.warn("Command has not been processed [itemName={}, command={}]", itemName, command);
        }
        return executedSuccessfully;
    }
    return false;
}
Also used : UpDownType(org.openhab.core.library.types.UpDownType) StopMoveType(org.openhab.core.library.types.StopMoveType) UrtsiBindingProvider(org.openhab.binding.urtsi.UrtsiBindingProvider)

Example 2 with StopMoveType

use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.

the class ZWaveMultiLevelSwitchConverter method receiveCommand.

/**
     * {@inheritDoc}
     */
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveMultiLevelSwitchCommandClass commandClass, int endpointId, Map<String, String> arguments) {
    SerialMessage serialMessage = null;
    String restoreLastValue = null;
    if (command instanceof StopMoveType && (StopMoveType) command == StopMoveType.STOP) {
        // special handling for the STOP command
        serialMessage = commandClass.stopLevelChangeMessage();
    } else {
        ZWaveCommandConverter<?, ?> converter = null;
        if (command instanceof OnOffType) {
            restoreLastValue = arguments.get("restore_last_value");
            if ("true".equalsIgnoreCase(restoreLastValue)) {
                converter = this.restoreValueOnOffConverter;
            } else {
                converter = this.normalOnOffConverter;
            }
        } else {
            converter = this.getCommandConverter(command.getClass());
        }
        if (converter == null) {
            logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
            return;
        }
        // Allow inversion of roller shutter UP/DOWN
        if (converter instanceof MultiLevelUpDownCommandConverter) {
            logger.debug("Multilevel Switch MultiLevelUpDownCommandConverter");
            if ("true".equalsIgnoreCase(arguments.get("invert_state"))) {
                logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - invert");
                if (command == UpDownType.UP) {
                    command = UpDownType.DOWN;
                } else {
                    command = UpDownType.UP;
                }
                logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - inverted: {}", command);
            }
        }
        // Allow inversion of roller shutter PERCENT value
        if (converter instanceof MultiLevelPercentCommandConverter) {
            logger.debug("Multilevel Switch MultiLevelPercentCommandConverter");
            if ("true".equalsIgnoreCase(arguments.get("invert_percent"))) {
                logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - invert");
                command = new PercentType(100 - ((DecimalType) command).intValue());
                logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - inverted: {}", command);
            }
        }
        Integer value = (Integer) converter.convertFromCommandToValue(item, command);
        logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), command.toString(), value, item.getName(), endpointId);
        serialMessage = commandClass.setValueMessage(value);
    }
    // encapsulate the message in case this is a multi-instance node
    serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
    if (serialMessage == null) {
        logger.warn("Generating message failed for command class = {}, node = {}, endpoint = {}", commandClass.getCommandClass().getLabel(), node.getNodeId(), endpointId);
        return;
    }
    this.getController().sendData(serialMessage);
    // update the bus in case of normal dimming. schedule refresh in case of restore to last value dimming.
    if (!"true".equalsIgnoreCase(restoreLastValue) && command instanceof OnOffType && (OnOffType) command == OnOffType.ON) {
        executeRefresh(node, commandClass, endpointId, arguments);
    } else if (command instanceof State) {
        this.getEventPublisher().postUpdate(item.getName(), (State) command);
    }
}
Also used : MultiLevelUpDownCommandConverter(org.openhab.binding.zwave.internal.converter.command.MultiLevelUpDownCommandConverter) OnOffType(org.openhab.core.library.types.OnOffType) State(org.openhab.core.types.State) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) PercentType(org.openhab.core.library.types.PercentType) StopMoveType(org.openhab.core.library.types.StopMoveType) MultiLevelPercentCommandConverter(org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)

Example 3 with StopMoveType

use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.

the class FibaroFGRM222Converter method receiveCommand.

@Override
void receiveCommand(final Item item, final Command command, final ZWaveNode node, final FibaroFGRM222CommandClass commandClass, final int endpointId, final Map<String, String> arguments) {
    logger.debug("NODE {}: receiveCommand()", node.getNodeId());
    Command internalCommand = command;
    SerialMessage serialMessage = null;
    if (internalCommand instanceof StopMoveType && (StopMoveType) internalCommand == StopMoveType.STOP) {
        // special handling for the STOP command
        serialMessage = commandClass.stopLevelChangeMessage(arguments.get("type"));
    } else {
        ZWaveCommandConverter<?, ?> converter = this.getCommandConverter(command.getClass());
        if (converter == null) {
            logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
            return;
        }
        if (converter instanceof MultiLevelPercentCommandConverter) {
            internalCommand = new PercentType(100 - ((DecimalType) command).intValue());
        }
        Integer value = (Integer) converter.convertFromCommandToValue(item, internalCommand);
        if (value == 0) {
            value = 1;
        }
        logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), internalCommand.toString(), value, item.getName(), endpointId);
        serialMessage = commandClass.setValueMessage(value, arguments.get("type"));
    }
    // encapsulate the message in case this is a multi-instance node
    serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
    if (serialMessage == null) {
        logger.warn("NODE {}: Generating message failed for command class = {}, node = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId);
        return;
    }
    this.getController().sendData(serialMessage);
    if (command instanceof State) {
        this.getEventPublisher().postUpdate(item.getName(), (State) command);
    }
}
Also used : Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) PercentType(org.openhab.core.library.types.PercentType) StopMoveType(org.openhab.core.library.types.StopMoveType) MultiLevelPercentCommandConverter(org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)

Example 4 with StopMoveType

use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.

the class InsteonHubBinding method internalReceiveCommand.

@Override
protected void internalReceiveCommand(String itemName, Command command) {
    // get configuration for this item
    InsteonHubBindingConfig config = InsteonHubBindingConfigUtil.getConfigForItem(providers, itemName);
    if (config == null) {
        logger.error(BINDING_NAME + " received command for unknown item '" + itemName + "'");
        return;
    }
    // parse info from config
    BindingType type = config.getBindingType();
    String hubId = config.getDeviceInfo().getHubId();
    String deviceId = config.getDeviceInfo().getDeviceId();
    // lookup proxy from this configuration
    InsteonHubProxy proxy = proxies.get(hubId);
    if (proxy == null) {
        logger.error(BINDING_NAME + " received command for unknown hub id '" + hubId + "'");
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug(BINDING_NAME + " processing command '" + command + "' of type '" + command.getClass().getSimpleName() + "' for item '" + itemName + "'");
    }
    try {
        // process according to type
        if (type == BindingType.SWITCH) {
            // set value on or off
            if (command instanceof OnOffType) {
                proxy.setDevicePower(deviceId, command == OnOffType.ON);
            }
        } else if (type == BindingType.DIMMER) {
            // INSTEON Dimmer supports Dimmer and RollerShutter types
            if (command instanceof OnOffType) {
                // ON or OFF => Set level to 255 or 0
                int level = command == OnOffType.ON ? 255 : 0;
                proxy.setDeviceLevel(deviceId, level);
            } else if (command instanceof IncreaseDecreaseType) {
                // Increase/Decrease => Incremental Brighten/Dim
                InsteonHubAdjustmentType adjustmentType;
                if (command == IncreaseDecreaseType.INCREASE) {
                    adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
                } else {
                    adjustmentType = InsteonHubAdjustmentType.DIM;
                }
                if (setDimTimeout(itemName)) {
                    proxy.startDeviceAdjustment(deviceId, adjustmentType);
                }
            } else if (command instanceof UpDownType) {
                // Up/Down => Start Brighten/Dim
                InsteonHubAdjustmentType adjustmentType;
                if (command == UpDownType.UP) {
                    adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
                } else {
                    adjustmentType = InsteonHubAdjustmentType.DIM;
                }
                proxy.startDeviceAdjustment(deviceId, adjustmentType);
            } else if (command instanceof StopMoveType) {
                // Stop => Stop Brighten/Dim
                if (command == StopMoveType.STOP) {
                    proxy.stopDeviceAdjustment(deviceId);
                }
            } else {
                // set level from 0 to 100 percent value
                byte percentByte = Byte.parseByte(command.toString());
                float percent = percentByte * .01f;
                int level = (int) (255 * percent);
                proxy.setDeviceLevel(deviceId, level);
            }
        }
    } catch (Throwable t) {
        logger.error("Error processing command '" + command + "' for item '" + itemName + "'", t);
    }
}
Also used : UpDownType(org.openhab.core.library.types.UpDownType) StopMoveType(org.openhab.core.library.types.StopMoveType) InsteonHubProxy(org.openhab.binding.insteonhub.internal.hardware.InsteonHubProxy) OnOffType(org.openhab.core.library.types.OnOffType) BindingType(org.openhab.binding.insteonhub.internal.InsteonHubBindingConfig.BindingType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) InsteonHubAdjustmentType(org.openhab.binding.insteonhub.internal.hardware.InsteonHubAdjustmentType)

Example 5 with StopMoveType

use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.

the class KNXCoreTypeMapper method toDPTValue.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.binding.knx.config.KNXTypeMapper#toDPTValue(org.openhab.core.types.Type, java.lang.String)
     */
@Override
public String toDPTValue(Type type, String dptID) {
    DPT dpt;
    int mainNumber = getMainNumber(dptID);
    if (mainNumber == -1) {
        logger.error("toDPTValue couldn't identify mainnumber in dptID: {}", dptID);
        return null;
    }
    try {
        DPTXlator translator = TranslatorTypes.createTranslator(mainNumber, dptID);
        dpt = translator.getType();
    } catch (KNXException e) {
        e.printStackTrace();
        return null;
    }
    // check for HSBType first, because it extends PercentType as well
    if (type instanceof HSBType) {
        Color color = ((HSBType) type).toColor();
        return "r:" + Integer.toString(color.getRed()) + " g:" + Integer.toString(color.getGreen()) + " b:" + Integer.toString(color.getBlue());
    } else if (type instanceof OnOffType) {
        return type.equals(OnOffType.OFF) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof UpDownType) {
        return type.equals(UpDownType.UP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof IncreaseDecreaseType) {
        DPT valueDPT = ((DPTXlator3BitControlled.DPT3BitControlled) dpt).getControlDPT();
        return type.equals(IncreaseDecreaseType.DECREASE) ? valueDPT.getLowerValue() + " 5" : valueDPT.getUpperValue() + " 5";
    } else if (type instanceof OpenClosedType) {
        return type.equals(OpenClosedType.CLOSED) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof StopMoveType) {
        return type.equals(StopMoveType.STOP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof PercentType) {
        return type.toString();
    } else if (type instanceof DecimalType) {
        switch(mainNumber) {
            case 2:
                DPT valueDPT = ((DPTXlator1BitControlled.DPT1BitControlled) dpt).getValueDPT();
                switch(((DecimalType) type).intValue()) {
                    case 0:
                        return "0 " + valueDPT.getLowerValue();
                    case 1:
                        return "0 " + valueDPT.getUpperValue();
                    case 2:
                        return "1 " + valueDPT.getLowerValue();
                    default:
                        return "1 " + valueDPT.getUpperValue();
                }
            case 18:
                int intVal = ((DecimalType) type).intValue();
                if (intVal > 63) {
                    return "learn " + (intVal - 0x80);
                } else {
                    return "activate " + intVal;
                }
            default:
                return type.toString();
        }
    } else if (type instanceof StringType) {
        return type.toString();
    } else if (type instanceof DateTimeType) {
        return formatDateTime((DateTimeType) type, dptID);
    }
    logger.debug("toDPTValue: Couldn't get value for {} dpt id {} (no mapping).", type, dptID);
    return null;
}
Also used : KNXException(tuwien.auto.calimero.exception.KNXException) StringType(org.openhab.core.library.types.StringType) Color(java.awt.Color) DPT(tuwien.auto.calimero.dptxlator.DPT) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) Datapoint(tuwien.auto.calimero.datapoint.Datapoint) StopMoveType(org.openhab.core.library.types.StopMoveType) DateTimeType(org.openhab.core.library.types.DateTimeType) DPTXlator(tuwien.auto.calimero.dptxlator.DPTXlator) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DPTXlator3BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator3BitControlled) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) DPTXlator1BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator1BitControlled) HSBType(org.openhab.core.library.types.HSBType)

Aggregations

StopMoveType (org.openhab.core.library.types.StopMoveType)8 OnOffType (org.openhab.core.library.types.OnOffType)6 PercentType (org.openhab.core.library.types.PercentType)6 UpDownType (org.openhab.core.library.types.UpDownType)6 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)5 DecimalType (org.openhab.core.library.types.DecimalType)3 MultiLevelPercentCommandConverter (org.openhab.binding.zwave.internal.converter.command.MultiLevelPercentCommandConverter)2 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)2 DimmerItem (org.openhab.core.library.items.DimmerItem)2 HSBType (org.openhab.core.library.types.HSBType)2 StringType (org.openhab.core.library.types.StringType)2 Command (org.openhab.core.types.Command)2 State (org.openhab.core.types.State)2 SappException (com.github.paolodenti.jsapp.core.command.base.SappException)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 BindingType (org.openhab.binding.insteonhub.internal.InsteonHubBindingConfig.BindingType)1 InsteonHubAdjustmentType (org.openhab.binding.insteonhub.internal.hardware.InsteonHubAdjustmentType)1 InsteonHubProxy (org.openhab.binding.insteonhub.internal.hardware.InsteonHubProxy)1 MochadX10Command (org.openhab.binding.mochadx10.commands.MochadX10Command)1