Search in sources :

Example 16 with Command

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

the class IRtransGenericBindingProvider method getInetSocketAddresses.

/**
     * {@inheritDoc}
     */
@Override
public List<InetSocketAddress> getInetSocketAddresses(String itemName) {
    List<InetSocketAddress> theList = new ArrayList<InetSocketAddress>();
    for (Command command : getAllCommands(itemName)) {
        InetSocketAddress anAddress = null;
        try {
            anAddress = new InetSocketAddress(InetAddress.getByName(getHost(itemName, command)), getPort(itemName, command));
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        theList.add(anAddress);
    }
    return theList;
}
Also used : UnknownHostException(java.net.UnknownHostException) Command(org.openhab.core.types.Command) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Example 17 with Command

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

the class IRtransGenericBindingProvider method getQualifiedCommands.

/**
     * {@inheritDoc}
     */
@Override
public List<Command> getQualifiedCommands(String itemName, Command command) {
    List<Command> commands = new ArrayList<Command>();
    IRtransBindingConfig aConfig = (IRtransBindingConfig) bindingConfigs.get(itemName);
    for (Command aCommand : aConfig.keySet()) {
        if (aCommand == command) {
            commands.add(aCommand);
        } else {
            if (aCommand instanceof DecimalType) {
                commands.add(aCommand);
            }
        }
    }
    return commands;
}
Also used : Command(org.openhab.core.types.Command) ArrayList(java.util.ArrayList) DecimalType(org.openhab.core.library.types.DecimalType)

Example 18 with Command

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

the class KNXBinding method sendTypeToItemButNotToKnx.

private void sendTypeToItemButNotToKnx(GroupAddress destination, String itemName, Type type) {
    // we need to make sure that we won't send out this event to
    // the knx bus again, when receiving it on the openHAB bus
    ignoreEventList.add(itemName + type.toString());
    logger.trace("Added event (item='{}', type='{}') to the ignore event list", itemName, type.toString());
    if (type instanceof Command && isCommandGA(destination)) {
        eventPublisher.postCommand(itemName, (Command) type);
    } else if (type instanceof State) {
        eventPublisher.postUpdate(itemName, (State) type);
    } else {
        throw new IllegalClassException("Cannot process datapoint of type " + type.toString());
    }
    logger.trace("Processed event (item='{}', type='{}', destination='{}')", itemName, type.toString(), destination.toString());
}
Also used : Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) IllegalClassException(org.apache.commons.lang.IllegalClassException)

Example 19 with Command

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

the class LcnBinding method internalReceiveCommand.

/** {@inheritDoc} */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    final String itemName2 = itemName;
    final Command command2 = command;
    this.runOnRefreshThreadAsync(new LcnBindingNotification() {

        @Override
        public void execute() {
            for (LcnGenericBindingProvider provider : LcnBinding.this.providers) {
                LcnBindingConfig itemConfig = provider.getLcnItemConfig(itemName2);
                if (itemConfig != null) {
                    itemConfig.send(LcnBinding.this.connections, command2);
                }
            }
        }
    });
}
Also used : LcnBindingNotification(org.openhab.binding.lcn.common.LcnBindingNotification) Command(org.openhab.core.types.Command)

Example 20 with Command

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

the class LcnGenericBindingProvider method processBindingConfiguration.

/**
     * Item processing for the LCN bindings.
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    Matcher matcher = PATTERN_BINDING_GENERAL.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException(bindingConfig + "' contains no valid binding!");
    }
    matcher.reset();
    LcnBindingConfig bc = new LcnBindingConfig(item);
    while (matcher.find()) {
        String binding = matcher.group(1);
        if (binding != null && !binding.trim().isEmpty()) {
            String openHabCmd = null;
            String connId, lcnTarget;
            Matcher openHabMatcher = PATTERN_BINDING_WITH_OPENHAB.matcher(binding);
            Matcher pureMatcher = PATTERN_BINDING_PURE.matcher(binding);
            if (openHabMatcher.matches()) {
                openHabCmd = openHabMatcher.group(1);
                connId = openHabMatcher.group(2);
                lcnTarget = openHabMatcher.group(3);
            } else if (pureMatcher.matches()) {
                connId = pureMatcher.group(1);
                lcnTarget = pureMatcher.group(2);
            } else {
                throw new BindingConfigParseException("Invalid binding configuration for " + binding + "!");
            }
            String lcnShort = resolveMappings(lcnTarget, openHabCmd);
            if (lcnShort == null || lcnShort.equals(openHabCmd)) {
                lcnShort = lcnTarget;
            }
            Command cmd = openHabCmd == null ? TypeParser.parseCommand(new StringItem("").getAcceptedCommandTypes(), "") : openHabCmd.equals("%i") ? new StringType("%i") : TypeParser.parseCommand(item.getAcceptedCommandTypes(), openHabCmd);
            bc.add(new LcnBindingConfig.Mapping(cmd, connId, lcnShort));
        }
    }
    // Finished
    this.addBindingConfig(item, bc);
    for (LcnAddrMod addr : bc.getRelatedModules()) {
        HashSet<String> l = this.itemNamesByModulCache.get(addr);
        if (l == null) {
            l = new HashSet<String>();
            this.itemNamesByModulCache.put(addr, l);
        }
        l.add(item.getName());
    }
}
Also used : Matcher(java.util.regex.Matcher) Command(org.openhab.core.types.Command) StringType(org.openhab.core.library.types.StringType) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) StringItem(org.openhab.core.library.items.StringItem) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

Aggregations

Command (org.openhab.core.types.Command)61 ArrayList (java.util.ArrayList)20 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)14 State (org.openhab.core.types.State)12 Matcher (java.util.regex.Matcher)10 DecimalType (org.openhab.core.library.types.DecimalType)8 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)6 NikobusCommand (org.openhab.binding.nikobus.internal.core.NikobusCommand)6 SchedulerException (org.quartz.SchedulerException)6 StringType (org.openhab.core.library.types.StringType)5 JobDataMap (org.quartz.JobDataMap)5 JobDetail (org.quartz.JobDetail)5 Scheduler (org.quartz.Scheduler)5 Trigger (org.quartz.Trigger)5 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 IOException (java.io.IOException)4 SocketChannel (java.nio.channels.SocketChannel)4 IllegalClassException (org.apache.commons.lang.IllegalClassException)4 PercentType (org.openhab.core.library.types.PercentType)4