Search in sources :

Example 11 with ZWaveCommandClass

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass in project openhab1-addons by openhab.

the class ZWaveConverterHandler method getRefreshInterval.

/**
     * Get the refresh interval for an item binding
     *
     * @param provider
     *            the {@link ZWaveBindingProvider} that provides the item
     * @param itemName
     *            the name of the item to poll.
     */
@SuppressWarnings("unchecked")
public Integer getRefreshInterval(ZWaveBindingProvider provider, String itemName) {
    ZWaveBindingConfig bindingConfiguration = provider.getZwaveBindingConfig(itemName);
    ZWaveCommandClass commandClass;
    String commandClassName = bindingConfiguration.getArguments().get("command");
    // this binding is configured not to poll.
    if (bindingConfiguration.getRefreshInterval() != null && 0 == bindingConfiguration.getRefreshInterval()) {
        return 0;
    }
    ZWaveNode node = this.controller.getNode(bindingConfiguration.getNodeId());
    // ignore nodes that are not initialized.
    if (node == null) {
        return 0;
    }
    if (commandClassName != null) {
        // this is a report item, handle it with the report info converter.
        if (commandClassName.equalsIgnoreCase("info")) {
            return infoConverter.getRefreshInterval();
        }
        if (node.getNodeId() == this.controller.getOwnNodeId() && commandClassName.equalsIgnoreCase("switch_all")) {
            return 0;
        }
        commandClass = node.resolveCommandClass(CommandClass.getCommandClass(commandClassName), bindingConfiguration.getEndpoint());
        if (commandClass == null) {
            logger.warn("No command class found for item = {}, command class name = {}, using 0 refresh interval.", itemName, commandClassName);
            return 0;
        }
    } else {
        commandClass = resolveConverter(provider.getItem(itemName), node, bindingConfiguration.getEndpoint());
    }
    if (commandClass == null) {
        logger.warn("No converter found for item = {}, using 0 refresh interval.", itemName);
        return 0;
    }
    ZWaveCommandClassConverter<ZWaveCommandClass> converter = (ZWaveCommandClassConverter<ZWaveCommandClass>) getConverter(commandClass.getCommandClass());
    if (converter == null) {
        logger.warn("No converter found for item = {}, using 0 refresh interval.", itemName);
        return 0;
    }
    if (bindingConfiguration.getRefreshInterval() == null) {
        bindingConfiguration.setRefreshInterval(converter.getRefreshInterval());
    }
    return bindingConfiguration.getRefreshInterval();
}
Also used : ZWaveCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveBindingConfig(org.openhab.binding.zwave.ZWaveBindingConfig)

Aggregations

ZWaveCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass)11 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)6 CommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass.CommandClass)5 ZWaveMultiInstanceCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveMultiInstanceCommandClass)4 ZWaveSecurityCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSecurityCommandClass)4 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)4 ZWaveBindingConfig (org.openhab.binding.zwave.ZWaveBindingConfig)3 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)3 ZWaveAssociationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass)3 ZWaveVersionCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveVersionCommandClass)3 ZWaveCommandClassDynamicState (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClassDynamicState)2 ZWaveNodeNamingCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveNodeNamingCommandClass)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ZWaveDbAssociationGroup (org.openhab.binding.zwave.internal.config.ZWaveDbAssociationGroup)1 ZWaveDbCommandClass (org.openhab.binding.zwave.internal.config.ZWaveDbCommandClass)1 ZWaveDbConfigurationParameter (org.openhab.binding.zwave.internal.config.ZWaveDbConfigurationParameter)1 ZWaveProductDatabase (org.openhab.binding.zwave.internal.config.ZWaveProductDatabase)1 ZWaveDeviceClass (org.openhab.binding.zwave.internal.protocol.ZWaveDeviceClass)1 Basic (org.openhab.binding.zwave.internal.protocol.ZWaveDeviceClass.Basic)1