use of org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback in project openhab1-addons by openhab.
the class HomematicCommunicator method event.
/**
* Receives a message from the Homematic server and publishes the state to
* openHAB.
*/
@Override
public void event(String interfaceId, String addressWithChannel, String parameter, Object value) {
boolean isVariable = "".equals(addressWithChannel);
HomematicBindingConfig bindingConfig = null;
if (isVariable) {
bindingConfig = new VariableConfig(parameter);
} else {
bindingConfig = new DatapointConfig(HmInterface.parse(interfaceId), addressWithChannel, parameter);
}
String className = value == null ? "Unknown" : value.getClass().getSimpleName();
logger.debug("Received new ({}) value '{}' for {}", className, value, bindingConfig);
lastEventTime = System.currentTimeMillis();
final Event event = new Event(bindingConfig, value);
if (sentPressEvents.remove(event.getBindingConfig())) {
logger.debug("Echo PRESS_* event detected, ignoring: {}", event.getBindingConfig());
} else {
if (context.getStateHolder().isDatapointReloadInProgress() && !isVariable) {
context.getStateHolder().addToRefreshCache(event.getBindingConfig(), event.getNewValue());
}
event.setHmValueItem(context.getStateHolder().getState(event.getBindingConfig()));
if (event.getHmValueItem() != null) {
event.getHmValueItem().setValue(event.getNewValue());
new ProviderItemIterator().iterate(event.getBindingConfig(), new ProviderItemIteratorCallback() {
@Override
public void next(HomematicBindingConfig providerBindingConfig, Item item, Converter<?> converter) {
State state = converter.convertFromBinding(event.getHmValueItem());
context.getEventPublisher().postUpdate(item.getName(), state);
if (state == OnOffType.ON) {
executeBindingAction(providerBindingConfig);
if (event.isPressValueItem()) {
itemDisabler.add(providerBindingConfig);
}
}
}
});
} else {
logger.warn("Can't find {}, value is not published to openHAB!", event.getBindingConfig());
}
}
}
use of org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback in project openhab1-addons by openhab.
the class ItemDisabler method run.
/**
* Sends the OFF commands to the openHAB bus.
*/
@Override
public void run() {
Iterator<Map.Entry<HomematicBindingConfig, Long>> iterator = itemsToDisable.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<HomematicBindingConfig, Long> entry = iterator.next();
long diff = System.currentTimeMillis() - entry.getValue();
if (diff > MIN_AGE) {
new ProviderItemIterator().iterate(entry.getKey(), new ProviderItemIteratorCallback() {
@Override
public void next(HomematicBindingConfig providerBindingConfig, Item item, Converter<?> converter) {
HmValueItem hmValueItem = context.getStateHolder().getState(providerBindingConfig);
if (providerBindingConfig instanceof ProgramConfig || providerBindingConfig instanceof ActionConfig) {
context.getEventPublisher().postUpdate(item.getName(), OnOffType.OFF);
} else {
hmValueItem.setValue(converter.convertToBinding(OnOffType.OFF, hmValueItem));
State state = converter.convertFromBinding(hmValueItem);
context.getEventPublisher().postUpdate(item.getName(), state);
}
logger.debug("Disabled Item {} with binding {}", item.getName(), providerBindingConfig);
}
});
iterator.remove();
}
}
}
Aggregations