Search in sources :

Example 11 with Command

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

the class DimmerSteppingProfile 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 12 with Command

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

the class RollershutterProfile method valueChanged.

@Override
public void valueChanged(ParameterAddress parameterAddress, Value valueObject) {
    ButtonState buttonState = (ButtonState) valueObject;
    Command command = null;
    if (Parameter.O.name().equals(parameterAddress.getParameterId())) {
        switch(buttonState) {
            case PRESSED:
                if (belongsToLastShortButtonPress()) {
                    command = StopMoveType.STOP;
                    lastButtonShortPressTime = 0;
                    belongsToLastShortButtonPress = true;
                    buttonOPressedTime = System.currentTimeMillis();
                } else {
                    command = UpDownType.UP;
                    buttonOPressedTime = System.currentTimeMillis();
                }
                break;
            case RELEASED:
                if (isLongOButtonReleased()) {
                    command = StopMoveType.STOP;
                    buttonOPressedTime = 0;
                } else if (belongsToLastShortButtonPress) {
                    lastButtonShortPressTime = 0;
                    belongsToLastShortButtonPress = false;
                } else {
                    lastButtonShortPressTime = System.currentTimeMillis();
                }
                break;
        }
    } else if (Parameter.I.name().equals(parameterAddress.getParameterId())) {
        switch(buttonState) {
            case PRESSED:
                if (belongsToLastShortButtonPress()) {
                    command = StopMoveType.STOP;
                    lastButtonShortPressTime = 0;
                    belongsToLastShortButtonPress = true;
                    buttonIPressedTime = System.currentTimeMillis();
                } else {
                    command = UpDownType.DOWN;
                    buttonIPressedTime = System.currentTimeMillis();
                }
                break;
            case RELEASED:
                if (isLongIButtonReleased()) {
                    command = StopMoveType.STOP;
                    buttonIPressedTime = 0;
                } else if (belongsToLastShortButtonPress) {
                    lastButtonShortPressTime = 0;
                    belongsToLastShortButtonPress = false;
                } else {
                    lastButtonShortPressTime = System.currentTimeMillis();
                }
                break;
        }
    }
    logger.debug("Received new value {} for items {}", command, items);
    postCommand(command);
}
Also used : Command(org.openhab.core.types.Command) ButtonState(org.opencean.core.common.values.ButtonState)

Example 13 with Command

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

the class SwitchOnOffProfile method valueChanged.

@Override
public void valueChanged(ParameterAddress parameterAddress, Value valueObject) {
    Command command = null;
    if (buttonIPressed(parameterAddress)) {
        command = OnOffType.ON;
    } else if (buttonOPressed(parameterAddress)) {
        command = OnOffType.OFF;
    }
    postCommand(command);
}
Also used : Command(org.openhab.core.types.Command)

Example 14 with Command

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

the class ExpireBinding method internalReceiveUpdate.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveUpdate(final String itemName, final State newState) {
    logger.trace("Received update '{}' for item {}", newState, itemName);
    for (ExpireBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            Command expireCommand = provider.getExpireCommand(itemName);
            State expireState = provider.getExpireState(itemName);
            if ((expireCommand != null && expireCommand.equals(newState)) || (expireState != null && expireState.equals(newState))) {
                // New state is expired command or state -> no further action needed
                // remove expire trigger until next update or command
                itemExpireMap.remove(itemName);
                logger.debug("Item {} received update '{}'; stopping any future expiration.", itemName, newState);
            } else {
                // New state 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 15 with Command

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

the class IRtransBinding method parseDecodedCommand.

protected void parseDecodedCommand(String itemName, IrCommand theCommand, Command ohCommand) {
    if (theCommand != null) {
        // traverse the providers, for each provider, check each binding if it matches theCommand
        for (IRtransBindingProvider provider : providers) {
            if (provider.providesBindingFor(itemName)) {
                List<org.openhab.core.types.Command> commands = provider.getAllCommands(itemName);
                // first check if commands are defined, and that they have the correct DirectionType
                Iterator<org.openhab.core.types.Command> listIterator = commands.listIterator();
                while (listIterator.hasNext()) {
                    org.openhab.core.types.Command aCommand = listIterator.next();
                    IrCommand providerCommand = new IrCommand();
                    providerCommand.remote = provider.getRemote(itemName, aCommand);
                    providerCommand.command = provider.getIrCommand(itemName, aCommand);
                    if (aCommand == ohCommand) {
                        if (providerCommand.matches(theCommand)) {
                            List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName, aCommand);
                            State newState = null;
                            if (aCommand instanceof DecimalType) {
                                newState = createStateFromString(stateTypeList, theCommand.remote + "," + theCommand.command);
                            } else {
                                newState = createStateFromString(stateTypeList, aCommand.toString());
                            }
                            if (newState != null) {
                                eventPublisher.postUpdate(itemName, newState);
                            } else {
                                logger.warn("Can not create an Item State to match command {} on item {}  ", aCommand, itemName);
                            }
                        } else {
                            logger.info("The IRtrans command '{},{}' does not match the command '{}' of the binding configuration for item '{}'", new Object[] { theCommand.remote, theCommand.command, ohCommand, itemName });
                        }
                    }
                }
            }
        }
    }
}
Also used : Command(org.openhab.core.types.Command) IRtransBindingProvider(org.openhab.binding.irtrans.IRtransBindingProvider) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State) DecimalType(org.openhab.core.library.types.DecimalType)

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