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