Search in sources :

Example 1 with MiosBindingConfig

use of org.openhab.binding.mios.internal.config.MiosBindingConfig in project openhab1-addons by openhab.

the class MiosBinding method invokeMiosAction.

/**
     * {@inheritDoc}
     */
@Override
public boolean invokeMiosAction(String itemName, String actionName, List<Entry<String, Object>> params) {
    try {
        logger.debug("invokeMiosAction item {}, action {}, params {}", new Object[] { itemName, actionName, Integer.valueOf((params == null) ? 0 : params.size()) });
        boolean sent = false;
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("invokeMiosAction: Action call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
            return false;
        }
        if (!connector.isConnected()) {
            logger.warn("invokeMiosAction: Action call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
            return false;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if ((config != null) && (config instanceof DeviceBindingConfig)) {
                    connector.invokeAction((DeviceBindingConfig) config, actionName, params);
                    sent = true;
                } else {
                    logger.error("invokeMiosAction: Missing BindingConfig for item '{}', or not bound to a MiOS Device.", itemName);
                }
            }
        }
        return sent;
    } catch (Exception e) {
        logger.error("invokeMiosScene: Error handling command", e);
        return false;
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) DeviceBindingConfig(org.openhab.binding.mios.internal.config.DeviceBindingConfig) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 2 with MiosBindingConfig

use of org.openhab.binding.mios.internal.config.MiosBindingConfig in project openhab1-addons by openhab.

the class MiosBindingProviderImpl method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    try {
        MiosBindingConfig config = parseBindingConfig(context, item, bindingConfig);
        config.validateItemType(item);
        logger.debug("processBindingConfiguration: Adding Item '{}' Binding '{}', from '{}'", new Object[] { item.getName(), config, context });
        addBindingConfig(item, config);
    } catch (BindingConfigParseException bcpe) {
        logger.debug(String.format("processBindingConfiguration: Exception parsing/validating context '%s', item'%s', bindingConfig '%s'.  Exception is %s.", context, item, bindingConfig, bcpe.getMessage()));
        throw bcpe;
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 3 with MiosBindingConfig

use of org.openhab.binding.mios.internal.config.MiosBindingConfig in project openhab1-addons by openhab.

the class MiosBinding method invokeMiosScene.

/**
     * {@inheritDoc}
     */
@Override
public boolean invokeMiosScene(String itemName) {
    try {
        logger.debug("invokeMiosScene item {}", itemName);
        boolean sent = false;
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("invokeMiosScene: Scene call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
            return false;
        }
        if (!connector.isConnected()) {
            logger.warn("invokeMiosScene: Scene call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
            return false;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if ((config != null) && (config instanceof SceneBindingConfig)) {
                    connector.invokeScene((SceneBindingConfig) config);
                    sent = true;
                } else {
                    logger.error("invokeMiosScene: Missing BindingConfig for item '{}', or not bound to a MiOS Scene.", itemName);
                }
            }
        }
        return sent;
    } catch (Exception e) {
        logger.error("invokeMiosScene: Error handling command", e);
        return false;
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) ConfigurationException(org.osgi.service.cm.ConfigurationException) SceneBindingConfig(org.openhab.binding.mios.internal.config.SceneBindingConfig)

Example 4 with MiosBindingConfig

use of org.openhab.binding.mios.internal.config.MiosBindingConfig in project openhab1-addons by openhab.

the class MiosBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    try {
        logger.debug("internalReceiveCommand: itemName '{}', command '{}'", itemName, command);
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("Received command ({}) for item '{}' but no connector found for MiOS Unit '{}', ignoring", new Object[] { command.toString(), itemName, unitName });
            return;
        }
        if (!connector.isConnected()) {
            logger.warn("Received command ({}) for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", new Object[] { command.toString(), itemName, unitName });
            return;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if (config != null) {
                    ItemRegistry reg = miosProvider.getItemRegistry();
                    if (reg != null) {
                        Item item = reg.getItem(config.getItemName());
                        State state = item.getState();
                        connector.invokeCommand(config, command, state);
                    } else {
                        logger.warn("internalReceiveCommand: Missing ItemRegistry for item '{}' command '{}'", itemName, command);
                    }
                } else {
                    logger.trace("internalReceiveCommand: Missing BindingConfig for item '{}' command '{}'", itemName, command);
                }
            }
        }
    } catch (Exception e) {
        logger.error("Error handling command", e);
    }
}
Also used : Item(org.openhab.core.items.Item) MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) State(org.openhab.core.types.State) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) ItemRegistry(org.openhab.core.items.ItemRegistry) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 5 with MiosBindingConfig

use of org.openhab.binding.mios.internal.config.MiosBindingConfig in project openhab1-addons by openhab.

the class MiosBinding method internalPropertyUpdate.

private void internalPropertyUpdate(String property, State value, boolean incremental) throws Exception {
    int bound = 0;
    if (value == null) {
        logger.trace("internalPropertyUpdate: Value is null for Property '{}', ignored.", property);
        return;
    }
    for (BindingProvider provider : providers) {
        if (provider instanceof MiosBindingProvider) {
            MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
            for (String itemName : miosProvider.getItemNamesForProperty(property)) {
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if (config != null) {
                    // Transform whatever value we have, based upon the
                    // Transformation Service specified in the Binding
                    // Config.
                    State newValue = config.transformIn(value);
                    if (newValue != value) {
                        logger.trace("internalPropertyUpdate: transformation performed, from '{}' to '{}'", value, newValue);
                    }
                    //
                    if (incremental) {
                        logger.debug("internalPropertyUpdate: BOUND (Incr) Updating '{} {mios=\"{}\"}' to '{}'", itemName, property, newValue);
                        eventPublisher.postUpdate(itemName, newValue);
                    } else {
                        ItemRegistry reg = miosProvider.getItemRegistry();
                        State oldValue = reg.getItem(itemName).getState();
                        if ((oldValue == null && newValue != null) || (UnDefType.UNDEF.equals(oldValue) && !UnDefType.UNDEF.equals(newValue)) || !oldValue.equals(newValue)) {
                            logger.debug("internalPropertyUpdate: BOUND (Full) Updating '{} {mios=\"{}\"}' to '{}', was '{}'", new Object[] { itemName, property, newValue, oldValue });
                            eventPublisher.postUpdate(itemName, newValue);
                        } else {
                            logger.trace("internalPropertyUpdate: BOUND (Full) Ignoring '{} {mios=\"{}\"}' to '{}', was '{}'", new Object[] { itemName, property, newValue, oldValue });
                        }
                    }
                    bound++;
                } else {
                    logger.trace("internalPropertyUpdate: Found null BindingConfig for item '{}' property '{}'", itemName, property);
                }
            }
        }
    }
    if (bound == 0) {
        logger.trace("internalPropertyUpdate: NOT BOUND {mios=\"{}\"}, value={}", property, value);
    } else {
        logger.trace("internalPropertyUpdate: BOUND {mios=\"{}\"}, value={}, bound {} time(s)", new Object[] { property, value, bound });
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) State(org.openhab.core.types.State) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) ItemRegistry(org.openhab.core.items.ItemRegistry)

Aggregations

MiosBindingConfig (org.openhab.binding.mios.internal.config.MiosBindingConfig)5 MiosBindingProvider (org.openhab.binding.mios.MiosBindingProvider)4 BindingProvider (org.openhab.core.binding.BindingProvider)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)3 ItemRegistry (org.openhab.core.items.ItemRegistry)2 State (org.openhab.core.types.State)2 DeviceBindingConfig (org.openhab.binding.mios.internal.config.DeviceBindingConfig)1 SceneBindingConfig (org.openhab.binding.mios.internal.config.SceneBindingConfig)1 Item (org.openhab.core.items.Item)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1