Search in sources :

Example 1 with SatelBindingConfig

use of org.openhab.binding.satel.SatelBindingConfig in project openhab1-addons by openhab.

the class SatelBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    if (!isProperlyConfigured()) {
        logger.warn("Binding not properly configured, exiting");
        return;
    }
    if (!this.satelModule.isInitialized()) {
        logger.debug("Module not initialized yet, ignoring command");
        return;
    }
    for (SatelBindingProvider provider : providers) {
        SatelBindingConfig itemConfig = provider.getItemConfig(itemName);
        if (itemConfig != null) {
            logger.trace("Sending internal command for item {}: {}", itemName, command);
            SatelCommand satelCmd = itemConfig.convertCommand(command, this.satelModule.getIntegraType(), getUserCode());
            if (satelCmd != null) {
                this.satelModule.sendCommand(satelCmd);
            }
            break;
        }
    }
}
Also used : SatelBindingProvider(org.openhab.binding.satel.SatelBindingProvider) SatelCommand(org.openhab.binding.satel.command.SatelCommand) SatelBindingConfig(org.openhab.binding.satel.SatelBindingConfig)

Example 2 with SatelBindingConfig

use of org.openhab.binding.satel.SatelBindingConfig in project openhab1-addons by openhab.

the class SatelGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    logger.trace("Processing binding configuration for item {}", item.getName());
    SatelBindingConfig bc = bindingConfigFactory.createBindingConfig(bindingConfig);
    logger.trace("Adding binding configuration for item {}: {}", item.getName(), bc);
    addBindingConfig(item, bc);
    super.processBindingConfiguration(context, item, bindingConfig);
}
Also used : SatelBindingConfig(org.openhab.binding.satel.SatelBindingConfig)

Example 3 with SatelBindingConfig

use of org.openhab.binding.satel.SatelBindingConfig in project openhab1-addons by openhab.

the class SatelBindingConfigFactory method createBindingConfig.

/**
     * Creates binding configuration class basing on given configuration string.
     * 
     * @param bindingConfig
     *            configuration string
     * @return an instance of {@link SatelBindingConfig}
     * @throws BindingConfigParseException
     *             on any parsing error
     */
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException {
    try {
        for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) {
            Method parseConfigMethod = c.getMethod("parseConfig", String.class);
            SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig);
            if (bc != null) {
                return bc;
            }
        }
    // no more options, throw parse exception
    } catch (Exception e) {
    // throw parse exception in case of any error
    }
    throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig));
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) Method(java.lang.reflect.Method) SatelBindingConfig(org.openhab.binding.satel.SatelBindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 4 with SatelBindingConfig

use of org.openhab.binding.satel.SatelBindingConfig in project openhab1-addons by openhab.

the class SatelBinding method incomingEvent.

/**
     * {@inheritDoc}
     */
@Override
public void incomingEvent(SatelEvent event) {
    logger.trace("Handling incoming event: {}", event);
    // refresh all states that have changed
    if (event instanceof NewStatesEvent) {
        List<SatelCommand> commands = getRefreshCommands((NewStatesEvent) event);
        for (SatelCommand command : commands) {
            this.satelModule.sendCommand(command);
        }
    }
    // if just connected, force refreshing
    if (event instanceof ConnectionStatusEvent) {
        ConnectionStatusEvent statusEvent = (ConnectionStatusEvent) event;
        if (statusEvent.isConnected()) {
            switchForceRefresh(true);
        }
    }
    // update items
    for (SatelBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            SatelBindingConfig itemConfig = provider.getItemConfig(itemName);
            Item item = provider.getItem(itemName);
            State newState = itemConfig.convertEventToState(item, event);
            if (newState != null) {
                logger.debug("Updating item state: item = {}, state = {}, event = {}", itemName, newState, event);
                eventPublisher.postUpdate(itemName, newState);
                itemConfig.setItemInitialized();
            }
        }
    }
}
Also used : Item(org.openhab.core.items.Item) SatelBindingProvider(org.openhab.binding.satel.SatelBindingProvider) ConnectionStatusEvent(org.openhab.binding.satel.internal.event.ConnectionStatusEvent) State(org.openhab.core.types.State) NewStatesEvent(org.openhab.binding.satel.internal.event.NewStatesEvent) SatelCommand(org.openhab.binding.satel.command.SatelCommand) SatelBindingConfig(org.openhab.binding.satel.SatelBindingConfig)

Example 5 with SatelBindingConfig

use of org.openhab.binding.satel.SatelBindingConfig in project openhab1-addons by openhab.

the class SatelBinding method getRefreshCommands.

private List<SatelCommand> getRefreshCommands(NewStatesEvent nse) {
    logger.trace("Gathering refresh commands from all items");
    boolean forceRefresh = switchForceRefresh(false);
    List<SatelCommand> commands = new LinkedList<SatelCommand>();
    for (SatelBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            logger.trace("Getting refresh command from item: {}", itemName);
            SatelBindingConfig itemConfig = provider.getItemConfig(itemName);
            SatelCommand command = itemConfig.buildRefreshCommand(this.satelModule.getIntegraType());
            if (command == null || commands.contains(command)) {
                continue;
            }
            // either state has changed or this is status command (so likely RTC has changed)
            // also if item hasn't received any update yet or refresh is forced
            // get the latest value from the module
            byte commandCode = command.getRequest().getCommand();
            if (forceRefresh || !itemConfig.isItemInitialized() || (nse != null && nse.isNew(commandCode)) || commandCode == IntegraStatusCommand.COMMAND_CODE) {
                commands.add(command);
            }
        }
    }
    return commands;
}
Also used : SatelBindingProvider(org.openhab.binding.satel.SatelBindingProvider) SatelCommand(org.openhab.binding.satel.command.SatelCommand) SatelBindingConfig(org.openhab.binding.satel.SatelBindingConfig) LinkedList(java.util.LinkedList)

Aggregations

SatelBindingConfig (org.openhab.binding.satel.SatelBindingConfig)5 SatelBindingProvider (org.openhab.binding.satel.SatelBindingProvider)3 SatelCommand (org.openhab.binding.satel.command.SatelCommand)3 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 ConnectionStatusEvent (org.openhab.binding.satel.internal.event.ConnectionStatusEvent)1 NewStatesEvent (org.openhab.binding.satel.internal.event.NewStatesEvent)1 Item (org.openhab.core.items.Item)1 State (org.openhab.core.types.State)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1