Search in sources :

Example 1 with DatapointConfig

use of org.openhab.binding.homematic.internal.config.binding.DatapointConfig 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 DatapointConfig

use of org.openhab.binding.homematic.internal.config.binding.DatapointConfig 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 DatapointConfig

use of org.openhab.binding.homematic.internal.config.binding.DatapointConfig in project openhab1-addons by openhab.

the class CcuClient method addRssiDatapoint.

/**
     * Generates a missing RSSI datapoint, workaround for a CCU bug.
     */
private void addRssiDatapoint(HmChannel channel, String name, Object value, HmValueItemIteratorCallback callback) {
    HmDatapoint dp = new HmDatapoint();
    dp.setName(name);
    dp.setValueType(8);
    dp.setWriteable(false);
    dp.setValue(value);
    channel.addDatapoint(dp);
    DatapointConfig bindingConfig = new DatapointConfig(channel.getDevice().getAddress(), channel.getNumber(), dp.getName());
    callback.iterate(bindingConfig, dp);
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 4 with DatapointConfig

use of org.openhab.binding.homematic.internal.config.binding.DatapointConfig in project openhab1-addons by openhab.

the class BindingConfigParser method parse.

/**
     * Parses the bindingConfig of an item and returns a HomematicBindingConfig.
     */
public HomematicBindingConfig parse(Item item, String bindingConfig) throws BindingConfigParseException {
    bindingConfig = StringUtils.trimToEmpty(bindingConfig);
    bindingConfig = StringUtils.removeStart(bindingConfig, "{");
    bindingConfig = StringUtils.removeEnd(bindingConfig, "}");
    String[] entries = bindingConfig.split("[,]");
    HomematicBindingConfigHelper helper = new HomematicBindingConfigHelper();
    for (String entry : entries) {
        String[] entryParts = StringUtils.trimToEmpty(entry).split("[=]");
        if (entryParts.length != 2) {
            throw new BindingConfigParseException("Each entry must have a key and a value");
        }
        String key = StringUtils.trim(entryParts[0]);
        // convert entry id to device if necessary
        if ("id".equalsIgnoreCase(key)) {
            logger.info("Please change the Homematic binding with the attribute 'id' to 'address' in entry: " + entry + " -> " + StringUtils.replace(entry, "id=", "address="));
            key = "address";
        }
        String value = StringUtils.trim(entryParts[1]);
        value = StringUtils.removeStart(value, "\"");
        value = StringUtils.removeEnd(value, "\"");
        try {
            helper.getClass().getDeclaredField(key).set(helper, value);
        } catch (Exception e) {
            throw new BindingConfigParseException("Could not set value " + value + " for attribute " + key);
        }
    }
    Converter<?> converter = null;
    // if (helper.isValidDatapoint() || helper.isValidVariable()) {
    // converter = instantiateConverter(helper.converter);
    // }
    BindingAction bindingAction = getBindingAction(item, helper.action);
    if (helper.isValidDatapoint()) {
        return new DatapointConfig(helper.address, helper.channel, helper.parameter, converter, bindingAction, helper.isForceUpdate(), NumberUtils.toDouble(helper.delay));
    } else if (helper.isValidVariable()) {
        return new VariableConfig(helper.variable, converter, bindingAction, helper.isForceUpdate(), NumberUtils.toDouble(helper.delay));
    } else if (helper.isValidProgram()) {
        if (!acceptsOnOffType(item)) {
            throw new BindingConfigParseException("Programs can only be attached to items which accepts OnOffType commands, ignoring item " + item.getName());
        }
        return new ProgramConfig(helper.program, bindingAction);
    } else if (bindingAction != null) {
        return new ActionConfig(bindingAction);
    } else {
        throw new BindingConfigParseException("Invalid binding: " + bindingConfig);
    }
}
Also used : VariableConfig(org.openhab.binding.homematic.internal.config.binding.VariableConfig) ActionConfig(org.openhab.binding.homematic.internal.config.binding.ActionConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) BindingAction(org.openhab.binding.homematic.internal.config.BindingAction) ProgramConfig(org.openhab.binding.homematic.internal.config.binding.ProgramConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 5 with DatapointConfig

use of org.openhab.binding.homematic.internal.config.binding.DatapointConfig in project openhab1-addons by openhab.

the class RemoteControlOptionParser method getSymbols.

/**
     * Returns all possible symbols from the remote control.
     */
private String[] getSymbols() throws HomematicClientException {
    DatapointConfig dpConfig = new DatapointConfig(remoteControlAddress, "18", "SUBMIT");
    HmDatapoint rcDatapoint = (HmDatapoint) context.getStateHolder().getState(dpConfig);
    if (rcDatapoint == null) {
        throw new HomematicClientException("Address " + remoteControlAddress + " is not a Homematic remote control with a display");
    }
    List<String> symbols = new ArrayList<String>();
    for (HmDatapoint datapoint : rcDatapoint.getChannel().getDatapoints()) {
        if (datapoint.isWriteable() && datapoint.getValueType() == 2 && !"SUBMIT".equals(datapoint.getName())) {
            symbols.add(datapoint.getName());
        }
    }
    return symbols.toArray(new String[0]);
}
Also used : DatapointConfig(org.openhab.binding.homematic.internal.config.binding.DatapointConfig) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException) ArrayList(java.util.ArrayList) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Aggregations

DatapointConfig (org.openhab.binding.homematic.internal.config.binding.DatapointConfig)7 HmDatapoint (org.openhab.binding.homematic.internal.model.HmDatapoint)5 VariableConfig (org.openhab.binding.homematic.internal.config.binding.VariableConfig)2 HmChannel (org.openhab.binding.homematic.internal.model.HmChannel)2 HmDevice (org.openhab.binding.homematic.internal.model.HmDevice)2 HmValueItem (org.openhab.binding.homematic.internal.model.HmValueItem)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ProviderItemIteratorCallback (org.openhab.binding.homematic.internal.communicator.ProviderItemIterator.ProviderItemIteratorCallback)1 HomematicClientException (org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)1 BindingAction (org.openhab.binding.homematic.internal.config.BindingAction)1 ActionConfig (org.openhab.binding.homematic.internal.config.binding.ActionConfig)1 HomematicBindingConfig (org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig)1 ProgramConfig (org.openhab.binding.homematic.internal.config.binding.ProgramConfig)1 HmDeviceList (org.openhab.binding.homematic.internal.model.HmDeviceList)1 HmRssiInfo (org.openhab.binding.homematic.internal.model.HmRssiInfo)1 Item (org.openhab.core.items.Item)1 State (org.openhab.core.types.State)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1