Search in sources :

Example 1 with HomematicBindingConfig

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);
    }
}
Also used : Item(org.openhab.core.items.Item) HomematicBindingProvider(org.openhab.binding.homematic.HomematicBindingProvider) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)

Example 2 with HomematicBindingConfig

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);
    }
}
Also used : Item(org.openhab.core.items.Item) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig) TimerTask(java.util.TimerTask)

Example 3 with HomematicBindingConfig

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);
    }
}
Also used : Item(org.openhab.core.items.Item) HomematicBindingProvider(org.openhab.binding.homematic.HomematicBindingProvider) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)

Example 4 with HomematicBindingConfig

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());
        }
    }
}
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 5 with HomematicBindingConfig

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

HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)9 Item (org.openhab.core.items.Item)6 HmValueItem (org.openhab.binding.homematic.internal.model.HmValueItem)4 HomematicBindingProvider (org.openhab.binding.homematic.HomematicBindingProvider)3 ProviderItemIteratorCallback (org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback)2 HmValueItemIteratorCallback (org.openhab.binding.homematic.internal.communicator.client.BaseHomematicClient.HmValueItemIteratorCallback)2 State (org.openhab.core.types.State)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TimerTask (java.util.TimerTask)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