use of org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig in project openhab1-addons by openhab.
the class HomematicBinding method internalReceiveUpdate.
/**
* Receives a state and send it to the Homematic communicator.
*/
@Override
protected void internalReceiveUpdate(String itemName, State newState) {
for (HomematicBindingProvider provider : providers) {
Item item = provider.getItem(itemName);
HomematicBindingConfig config = provider.getBindingFor(itemName);
communicator.receiveUpdate(item, newState, config);
}
}
use of org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig in project openhab1-addons by openhab.
the class HomematicBinding method informCommunicator.
/**
* Schedules a job with a short delay to populate changed items to openHAB
* after startup or an item reload.
*
* @see BindingChangedDelayedExecutor
*/
private void informCommunicator(HomematicBindingProvider hmProvider, String itemName) {
final Item item = hmProvider.getItem(itemName);
final HomematicBindingConfig bindingConfig = hmProvider.getBindingFor(itemName);
if (bindingConfig != null) {
delayedExecutor.cancel();
delayedExecutor.addBindingConfig(item, bindingConfig);
delayedExecutor.schedule(new TimerTask() {
@Override
public void run() {
delayedExecutor.publishChangedBindings();
}
}, 3000);
}
}
use of org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig in project openhab1-addons by openhab.
the class HomematicBinding method internalReceiveCommand.
/**
* Receives a command and send it to the Homematic communicator.
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
for (HomematicBindingProvider provider : providers) {
Item item = provider.getItem(itemName);
HomematicBindingConfig config = provider.getBindingFor(itemName);
communicator.receiveCommand(item, command, config);
}
}
use of org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig 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.config.binding.HomematicBindingConfig 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