Search in sources :

Example 1 with HmValueItem

use of org.openhab.binding.homematic.internal.model.HmValueItem 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)

Example 2 with HmValueItem

use of org.openhab.binding.homematic.internal.model.HmValueItem in project openhab1-addons by openhab.

the class RemoteControlOptionParser method getValueItems.

/**
     * Returns all possible value items from the remote control.
     */
private String[] getValueItems(String parameterName) {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", parameterName);
    HmValueItem hmValueItem = context.getStateHolder().getState(dpConfig);
    if (hmValueItem != null) {
        String[] valueList = (String[]) ArrayUtils.remove(hmValueItem.getValueList(), 0);
        int onIdx = ArrayUtils.indexOf(valueList, "ON");
        if (onIdx != -1) {
            valueList[onIdx] = parameterName + "_ON";
        }
        return valueList;
    }
    return new String[0];
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem)

Example 3 with HmValueItem

use of org.openhab.binding.homematic.internal.model.HmValueItem in project openhab1-addons by openhab.

the class StateHolder method loadDatapoints.

/**
     * Loads all datapoints from the Homematic server, only executed at startup.
     */
public void loadDatapoints() throws HomematicClientException {
    logger.info("Loading Homematic datapoints");
    context.getHomematicClient().iterateAllDatapoints(new HmValueItemIteratorCallback() {

        @Override
        public void iterate(HomematicBindingConfig bindingConfig, HmValueItem hmValueItem) {
            datapoints.put(bindingConfig, hmValueItem);
        }
    });
    logger.info("Finished loading {} Homematic datapoints", datapoints.size());
}
Also used : HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig) HmValueItemIteratorCallback(org.openhab.binding.homematic.internal.communicator.client.BaseHomematicClient.HmValueItemIteratorCallback) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem)

Example 4 with HmValueItem

use of org.openhab.binding.homematic.internal.model.HmValueItem in project openhab1-addons by openhab.

the class StateHolder method updateRssiInfo.

/**
     * Upates the RSSI datapoint if available.
     */
private void updateRssiInfo(DatapointConfig bindingConfig, Integer rssiValue) {
    HmValueItem valueItem = datapoints.get(bindingConfig);
    if (valueItem != null) {
        if (!valueItem.getValue().equals(rssiValue)) {
            logger.debug("Value changed from '{}' to '{}' for binding {}", valueItem == null ? "null" : valueItem.getValue(), rssiValue, bindingConfig);
            valueItem.setValue(rssiValue);
            publish(bindingConfig, valueItem);
        }
    } else {
        logger.debug("Rssi info not found: {}", bindingConfig);
    }
}
Also used : HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem)

Example 5 with HmValueItem

use of org.openhab.binding.homematic.internal.model.HmValueItem in project openhab1-addons by openhab.

the class HomematicCommunicator method publishChangedItemToOpenhab.

/**
     * Called on startup or when some binding has changed, for example if a item
     * file is reloaded. Publishes the current States to openHAB.
     */
public void publishChangedItemToOpenhab(Item item, HomematicBindingConfig bindingConfig) {
    HmValueItem hmValueItem = context.getStateHolder().getState(bindingConfig);
    if (hmValueItem != null) {
        Converter<?> converter = context.getConverterFactory().createConverter(item, bindingConfig);
        if (converter != null) {
            State state = converter.convertFromBinding(hmValueItem);
            context.getEventPublisher().postUpdate(item.getName(), state);
        }
    } else if (bindingConfig instanceof ProgramConfig || bindingConfig instanceof ActionConfig) {
        context.getEventPublisher().postUpdate(item.getName(), OnOffType.OFF);
    } else {
        logger.warn("Can't find {}, value is not published to openHAB!", bindingConfig);
    }
}
Also used : ActionConfig(org.openhab.binding.homematic.internal.config.binding.ActionConfig) State(org.openhab.core.types.State) ProgramConfig(org.openhab.binding.homematic.internal.config.binding.ProgramConfig) HmValueItem(org.openhab.binding.homematic.internal.model.HmValueItem)

Aggregations

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