Search in sources :

Example 1 with ZWaveBindingProvider

use of org.openhab.binding.zwave.ZWaveBindingProvider in project openhab1-addons by openhab.

the class ZWaveActiveBinding method internalReceiveCommand.

/**
     * Handles a command update by sending the appropriate Z-Wave instructions
     * to the controller.
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    boolean handled = false;
    // if we are not yet initialized, don't waste time and return
    if (this.isProperlyConfigured() == false) {
        logger.debug("internalReceiveCommand Called, But Not Properly Configure yet, returning.");
        return;
    }
    logger.trace("internalReceiveCommand(itemname = {}, Command = {})", itemName, command.toString());
    for (ZWaveBindingProvider provider : providers) {
        if (!provider.providesBindingFor(itemName)) {
            continue;
        }
        converterHandler.receiveCommand(provider, itemName, command);
        handled = true;
    }
    if (!handled) {
        logger.warn("No converter found for item = {}, command = {}, ignoring.", itemName, command.toString());
    }
}
Also used : ZWaveBindingProvider(org.openhab.binding.zwave.ZWaveBindingProvider)

Example 2 with ZWaveBindingProvider

use of org.openhab.binding.zwave.ZWaveBindingProvider in project openhab1-addons by openhab.

the class ZWaveActiveBinding method handleZWaveCommandClassValueEvent.

/**
     * Handle an incoming Command class value event
     *
     * @param event the incoming Z-Wave event.
     */
private void handleZWaveCommandClassValueEvent(ZWaveCommandClassValueEvent event) {
    boolean handled = false;
    logger.debug("NODE {}: Got a value event from Z-Wave network, endpoint = {}, command class = {}, value = {}", new Object[] { event.getNodeId(), event.getEndpoint(), event.getCommandClass().getLabel(), event.getValue() });
    for (ZWaveBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            ZWaveBindingConfig bindingConfig = provider.getZwaveBindingConfig(itemName);
            if (bindingConfig.getNodeId() != event.getNodeId() || bindingConfig.getEndpoint() != event.getEndpoint()) {
                continue;
            }
            converterHandler.handleEvent(provider, itemName, event);
            handled = true;
        }
    }
    if (!handled) {
        logger.warn("NODE {}: No item bound for event, endpoint = {}, command class = {}, value = {}, ignoring.", new Object[] { event.getNodeId(), event.getEndpoint(), event.getCommandClass().getLabel(), event.getValue() });
    }
}
Also used : ZWaveBindingProvider(org.openhab.binding.zwave.ZWaveBindingProvider) ZWaveBindingConfig(org.openhab.binding.zwave.ZWaveBindingConfig)

Example 3 with ZWaveBindingProvider

use of org.openhab.binding.zwave.ZWaveBindingProvider in project openhab1-addons by openhab.

the class ZWaveActiveBinding method bindingChanged.

/**
     * Called, if a single binding has changed. The given item could have been
     * added or removed. We refresh the binding in case it's in the done stage.
     *
     * @param provider the binding provider where the binding has changed
     * @param itemName the item name for which the binding has changed
     */
@Override
public void bindingChanged(BindingProvider provider, String itemName) {
    logger.trace("bindingChanged {}", itemName);
    ZWaveBindingProvider zProvider = (ZWaveBindingProvider) provider;
    if (zProvider != null) {
        ZWaveBindingConfig bindingConfig = zProvider.getZwaveBindingConfig(itemName);
        if (bindingConfig != null && converterHandler != null) {
            converterHandler.executeRefresh(zProvider, itemName, true);
        }
    }
    // Bindings have changed - rebuild the polling table
    rebuildPollingTable();
    super.bindingChanged(provider, itemName);
}
Also used : ZWaveBindingProvider(org.openhab.binding.zwave.ZWaveBindingProvider) ZWaveBindingConfig(org.openhab.binding.zwave.ZWaveBindingConfig)

Example 4 with ZWaveBindingProvider

use of org.openhab.binding.zwave.ZWaveBindingProvider in project openhab1-addons by openhab.

the class ZWaveActiveBinding method rebuildPollingTable.

/**
     * This method rebuilds the polling table. The polling table is a list of items that have
     * polling enabled (ie a refresh interval is set). This list is then checked periodically
     * and any item that has passed its polling interval will be polled.
     */
private void rebuildPollingTable() {
    // Rebuild the polling table
    pollingList.clear();
    if (converterHandler == null) {
        logger.debug("ConverterHandler not initialised. Polling disabled.");
        return;
    }
    // Loop all binding providers for the Z-wave binding.
    for (ZWaveBindingProvider eachProvider : providers) {
        // Loop all bound items for this provider
        for (String name : eachProvider.getItemNames()) {
            // Find the node and check if it's completed initialisation.
            ZWaveBindingConfig cfg = eachProvider.getZwaveBindingConfig(name);
            ZWaveNode node = this.zController.getNode(cfg.getNodeId());
            if (node == null) {
                logger.debug("NODE {}: Polling list: can't get node for item {}", cfg.getNodeId(), name);
                continue;
            }
            if (node.getNodeInitializationStage() != ZWaveNodeInitStage.DONE) {
                logger.debug("NODE {}: Polling list: item {} is not completed initialisation", cfg.getNodeId(), name);
                continue;
            }
            logger.trace("Polling list: Checking {} == {}", name, converterHandler.getRefreshInterval(eachProvider, name));
            // If this binding is configured to poll - add it to the list
            if (converterHandler.getRefreshInterval(eachProvider, name) > 0) {
                ZWavePollItem item = new ZWavePollItem();
                item.item = name;
                item.provider = eachProvider;
                pollingList.add(item);
                logger.trace("Polling list added {}", name);
            }
        }
    }
    pollingIterator = null;
}
Also used : ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveBindingProvider(org.openhab.binding.zwave.ZWaveBindingProvider) ZWaveBindingConfig(org.openhab.binding.zwave.ZWaveBindingConfig)

Aggregations

ZWaveBindingProvider (org.openhab.binding.zwave.ZWaveBindingProvider)4 ZWaveBindingConfig (org.openhab.binding.zwave.ZWaveBindingConfig)3 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)1