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);
}
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);
}
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);
}
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;
}
}
}
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 });
}
}
}
}
}
}
}
Aggregations