use of org.openhab.binding.expire.ExpireBindingProvider 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.binding.expire.ExpireBindingProvider 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;
}
}
}
Aggregations