Search in sources :

Example 1 with Item

use of org.openhab.core.items.Item 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 Item

use of org.openhab.core.items.Item 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 Item

use of org.openhab.core.items.Item 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 Item

use of org.openhab.core.items.Item 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 Item

use of org.openhab.core.items.Item 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

Item (org.openhab.core.items.Item)59 SwitchItem (org.openhab.core.library.items.SwitchItem)23 NumberItem (org.openhab.core.library.items.NumberItem)20 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)16 State (org.openhab.core.types.State)16 RollershutterItem (org.openhab.core.library.items.RollershutterItem)15 ContactItem (org.openhab.core.library.items.ContactItem)14 DimmerItem (org.openhab.core.library.items.DimmerItem)14 DecimalType (org.openhab.core.library.types.DecimalType)9 HistoricItem (org.openhab.core.persistence.HistoricItem)9 ArrayList (java.util.ArrayList)7 ColorItem (org.openhab.core.library.items.ColorItem)7 StringItem (org.openhab.core.library.items.StringItem)7 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)6 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6 Test (org.junit.Test)5 GenericItem (org.openhab.core.items.GenericItem)5 GroupItem (org.openhab.core.items.GroupItem)5 ItemRegistry (org.openhab.core.items.ItemRegistry)5 Calendar (java.util.Calendar)3