Search in sources :

Example 1 with ProviderItemIteratorCallback

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());
        }
    }
}
Also used : VariableConfig(org.openhab.binding.homematic.internal.config.binding.VariableConfig) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem) Item(org.openhab.core.items.Item) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig) State(org.openhab.core.types.State) ProviderItemIteratorCallback(org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback) DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig)

Example 2 with ProviderItemIteratorCallback

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();
        }
    }
}
Also used : ActionConfig(org.openhab.binding.homematic.internal.config.binding.ActionConfig) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem) Item(org.openhab.core.items.Item) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig) State(org.openhab.core.types.State) ProviderItemIteratorCallback(org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback) ProgramConfig(org.openhab.binding.homematic.internal.config.binding.ProgramConfig) HashMap(java.util.HashMap) Map(java.util.Map) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem)

Aggregations

ProviderItemIteratorCallback (org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback)2 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)2 HmValueItem (org.openhab.binding.homematic.internal.model.HmValueItem)2 Item (org.openhab.core.items.Item)2 State (org.openhab.core.types.State)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionConfig (org.openhab.binding.homematic.internal.config.binding.ActionConfig)1 DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)1 ProgramConfig (org.openhab.binding.homematic.internal.config.binding.ProgramConfig)1 VariableConfig (org.openhab.binding.homematic.internal.config.binding.VariableConfig)1