Search in sources :

Example 56 with Command

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

the class ExpireBinding method expire.

private void expire(String itemName, ExpireBindingProvider provider) {
    // disable expire trigger until next update or command
    itemExpireMap.remove(itemName);
    Command expireCommand = provider.getExpireCommand(itemName);
    State expireState = provider.getExpireState(itemName);
    if (expireCommand != null) {
        logger.debug("Item {} received no command or update for {} - posting command '{}'", itemName, provider.getDurationString(itemName), expireCommand);
        eventPublisher.postCommand(itemName, expireCommand);
    } else if (expireState != null) {
        logger.debug("Item {} received no command or update for {} - posting state '{}'", itemName, provider.getDurationString(itemName), expireState);
        eventPublisher.postUpdate(itemName, expireState);
    }
}
Also used : Command(org.openhab.core.types.Command) State(org.openhab.core.types.State)

Example 57 with Command

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

the class ExpireBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(final String itemName, final Command newCommand) {
    logger.trace("Received command '{}' for item {}", newCommand, itemName);
    for (ExpireBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            Command expireCommand = provider.getExpireCommand(itemName);
            State expireState = provider.getExpireState(itemName);
            if ((expireCommand != null && expireCommand.equals(newCommand)) || (expireState != null && expireState.equals(newCommand))) {
                // New command is expired command or state -> no further action needed
                // remove expire trigger until next update or command
                itemExpireMap.remove(itemName);
                logger.debug("Item {} received command '{}'; stopping any future expiration.", itemName, newCommand);
            } else {
                // New command is not the expired command or state, so add the trigger to the map
                long duration = provider.getDuration(itemName);
                itemExpireMap.put(itemName, System.currentTimeMillis() + duration);
                logger.debug("Item {} will expire (with '{}' {}) in {} ms", itemName, expireCommand == null ? expireState : expireCommand, expireCommand == null ? "state" : "command", duration);
            }
            break;
        }
    }
}
Also used : ExpireBindingProvider(org.openhab.binding.expire.ExpireBindingProvider) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State)

Example 58 with Command

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

the class DimmerOnOffProfile method valueChanged.

@Override
public void valueChanged(ParameterAddress parameterAddress, Value valueObject) {
    ButtonState buttonState = (ButtonState) valueObject;
    Command command = null;
    if (buttonDownPressed(parameterAddress)) {
        switch(buttonState) {
            case PRESSED:
                startDimmerThread(IncreaseDecreaseType.INCREASE);
                buttonOPressedTime = System.currentTimeMillis();
                break;
            case RELEASED:
                stopDimmerThread();
                if (isLongOButtonReleased()) {
                    buttonOPressedTime = 0;
                } else {
                    command = OnOffType.ON;
                }
                break;
        }
    } else if (buttonUpPressed(parameterAddress)) {
        switch(buttonState) {
            case PRESSED:
                startDimmerThread(IncreaseDecreaseType.DECREASE);
                buttonIPressedTime = System.currentTimeMillis();
                break;
            case RELEASED:
                stopDimmerThread();
                if (isLongIButtonReleased()) {
                    buttonIPressedTime = 0;
                } else {
                    command = OnOffType.OFF;
                }
                break;
        }
    }
    postCommand(command);
}
Also used : Command(org.openhab.core.types.Command) ButtonState(org.opencean.core.common.values.ButtonState)

Example 59 with Command

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

the class SonosGenericBindingProvider method getItemNames.

@Override
public List<String> getItemNames(String sonosID, String sonosCommand) {
    List<String> result = new ArrayList<String>();
    Collection<String> items = getItemNames();
    for (String anItem : items) {
        SonosBindingConfig aBindingConfig = (SonosBindingConfig) bindingConfigs.get(anItem);
        for (Command command : aBindingConfig.keySet()) {
            SonosBindingConfigElement anElement = aBindingConfig.get(command);
            if (anElement.getSonosCommand().equals(sonosCommand) && anElement.getSonosID().equals(sonosID) && !result.contains(anItem)) {
                result.add(anItem);
            }
        }
    }
    return result;
}
Also used : Command(org.openhab.core.types.Command) ArrayList(java.util.ArrayList)

Example 60 with Command

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

the class ProtocolGenericBindingProvider method getAllCommands.

@Override
public List<Command> getAllCommands(String itemName, String protocolCommand) {
    List<Command> commands = new ArrayList<Command>();
    ProtocolBindingConfig aConfig = (ProtocolBindingConfig) bindingConfigs.get(itemName);
    if (aConfig != null) {
        for (Command aCommand : aConfig.keySet()) {
            ProtocolBindingConfigElement anElement = aConfig.get(aCommand);
            if (anElement.networkCommand.equals(protocolCommand)) {
                commands.add(aCommand);
            }
        }
    }
    return commands;
}
Also used : Command(org.openhab.core.types.Command) ArrayList(java.util.ArrayList)

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