Search in sources :

Example 1 with ThingTypeUID

use of org.openhab.core.thing.ThingTypeUID in project org.openhab.binding.zwave by openhab.

the class ZWaveDiscoveryService method deviceDiscovered.

/**
 * Initial device discovered call.
 * This is called when the device is first found. We know very little about the device at
 * this stage - just its node number. We add this to the inbox so the users have feedback
 * that the device is included into the network.
 *
 * {@link #deviceAdded} is called once more information is known about the device to add
 * manufacturer information and other properties.
 *
 * @param nodeId the node to be added
 */
public void deviceDiscovered(int nodeId) {
    // Don't add the controller as a thing, and only add valid nodes
    if (controllerHandler.getOwnNodeId() == nodeId || nodeId == 0 || nodeId > 232) {
        return;
    }
    ThingUID bridgeUID = controllerHandler.getThing().getUID();
    ThingUID thingUID = new ThingUID(new ThingTypeUID(ZWaveBindingConstants.ZWAVE_THING), bridgeUID, String.format("node%d", nodeId));
    logger.debug("NODE {}: Device discovered", nodeId);
    Map<String, Object> properties = new HashMap<>(1);
    properties.put(ZWaveBindingConstants.PROPERTY_NODEID, Integer.toString(nodeId));
    properties.put(ZWaveBindingConstants.CONFIGURATION_NODEID, new BigDecimal(nodeId));
    DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID).withProperties(properties).withLabel(String.format(ZWAVE_NODE_LABEL, nodeId)).build();
    thingDiscovered(discoveryResult);
}
Also used : DiscoveryResult(org.openhab.core.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.openhab.core.thing.ThingUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) BigDecimal(java.math.BigDecimal)

Example 2 with ThingTypeUID

use of org.openhab.core.thing.ThingTypeUID in project org.openhab.binding.zwave by openhab.

the class ZWaveDiscoveryService method deviceAdded.

/**
 * This is called once the node is fully discovered. At this point we know most of the information about
 * the device including manufacturer information.
 *
 * @param node the node to be added
 */
public void deviceAdded(ZWaveNode node) {
    // Don't add the controller as a thing, and only add valid nodes
    if (controllerHandler.getOwnNodeId() == node.getNodeId() || node.getNodeId() == 0 || node.getNodeId() > 232) {
        return;
    }
    logger.debug("NODE {}: Device discovery completed", node.getNodeId());
    ThingUID bridgeUID = controllerHandler.getThing().getUID();
    // Search the database for this product information
    ZWaveProduct foundProduct = null;
    for (ZWaveProduct product : ZWaveConfigProvider.getProductIndex()) {
        if (product == null) {
            continue;
        }
        logger.trace("NODE {}: Checking {}", node.getNodeId(), product.getThingTypeUID());
        if (product.match(node) == true) {
            foundProduct = product;
            break;
        }
    }
    ThingTypeUID thingTypeUID;
    // If we didn't find the product, then add the unknown thing
    String label = String.format(ZWAVE_NODE_LABEL, node.getNodeId());
    if (foundProduct == null) {
        if (node.getManufacturer() != Integer.MAX_VALUE) {
            logger.warn("NODE {}: Device discovery could not resolve to a thingType! {}:{}:{}::{}", node.getNodeId(), String.format("%04X", node.getManufacturer()), String.format("%04X", node.getDeviceType()), String.format("%04X", node.getDeviceId()), node.getApplicationVersion());
            label += String.format(" (%04X:%04X:%04X:%s)", node.getManufacturer(), node.getDeviceType(), node.getDeviceId(), node.getApplicationVersion());
        } else {
            logger.warn("NODE {}: Device discovery could not resolve to a thingType! Manufacturer data not known.", node.getNodeId());
        }
        thingTypeUID = new ThingTypeUID(ZWaveBindingConstants.ZWAVE_THING);
    } else {
        logger.debug("NODE {}: Device discovery resolved to thingType {}", node.getNodeId(), foundProduct.getThingTypeUID());
        // And create the new thing
        ThingType thingType = ZWaveConfigProvider.getThingType(foundProduct.getThingTypeUID());
        label += String.format(": %s", thingType.getLabel());
        thingTypeUID = foundProduct.getThingTypeUID();
    }
    // thingTypeUID = new ThingTypeUID(ZWaveBindingConstants.ZWAVE_THING);
    // Create the thing UID
    ThingUID thingUID = new ThingUID(new ThingTypeUID(ZWaveBindingConstants.ZWAVE_THING), bridgeUID, String.format("node%d", node.getNodeId()));
    // Add some device properties that might be useful for the system to know
    Map<String, Object> properties = new HashMap<>(11);
    properties.put(ZWaveBindingConstants.CONFIGURATION_NODEID, new BigDecimal(node.getNodeId()));
    // This should also prevent it from being overwritten if it was added previously
    if (node.getManufacturer() != Integer.MAX_VALUE) {
        properties.put(ZWaveBindingConstants.PROPERTY_MANUFACTURER, Integer.toString(node.getManufacturer()));
        properties.put(ZWaveBindingConstants.PROPERTY_DEVICETYPE, Integer.toString(node.getDeviceType()));
        properties.put(ZWaveBindingConstants.PROPERTY_DEVICEID, Integer.toString(node.getDeviceId()));
    }
    properties.put(ZWaveBindingConstants.PROPERTY_VERSION, node.getApplicationVersion());
    // The following properties should always be known as they come from the controller
    properties.put(ZWaveBindingConstants.PROPERTY_CLASS_BASIC, node.getDeviceClass().getBasicDeviceClass().toString());
    properties.put(ZWaveBindingConstants.PROPERTY_CLASS_GENERIC, node.getDeviceClass().getGenericDeviceClass().toString());
    properties.put(ZWaveBindingConstants.PROPERTY_CLASS_SPECIFIC, node.getDeviceClass().getSpecificDeviceClass().toString());
    properties.put(ZWaveBindingConstants.PROPERTY_LISTENING, Boolean.toString(node.isListening()));
    properties.put(ZWaveBindingConstants.PROPERTY_FREQUENT, Boolean.toString(node.isFrequentlyListening()));
    properties.put(ZWaveBindingConstants.PROPERTY_BEAMING, Boolean.toString(node.isBeaming()));
    properties.put(ZWaveBindingConstants.PROPERTY_ROUTING, Boolean.toString(node.isRouting()));
    // Create the discovery result and add to the inbox
    DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withProperties(properties).withBridge(bridgeUID).withLabel(label).build();
    thingDiscovered(discoveryResult);
    return;
}
Also used : DiscoveryResult(org.openhab.core.config.discovery.DiscoveryResult) ZWaveProduct(org.openhab.binding.zwave.internal.ZWaveProduct) HashMap(java.util.HashMap) ThingUID(org.openhab.core.thing.ThingUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ThingType(org.openhab.core.thing.type.ThingType) BigDecimal(java.math.BigDecimal)

Example 3 with ThingTypeUID

use of org.openhab.core.thing.ThingTypeUID in project org.openhab.binding.zwave by openhab.

the class ZWaveConfigProvider method getConfigDescription.

@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (!"thing".equals(uri.getScheme()) && !"thing-type".equals(uri.getScheme())) {
        return null;
    }
    ThingTypeUID thingTypeUID = new ThingTypeUID(uri.getSchemeSpecificPart());
    // Is this a zwave thing?
    if (!thingTypeUID.getBindingId().equals(ZWaveBindingConstants.BINDING_ID)) {
        return null;
    }
    List<ConfigDescriptionParameter> parameters = new ArrayList<ConfigDescriptionParameter>();
    if ("thing-type".equals(uri.getScheme())) {
        if (uri.getSchemeSpecificPart().equals(ZWaveBindingConstants.CONTROLLER_SERIAL.toString())) {
            return null;
        }
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODEID, Type.INTEGER).withLabel("Node ID").withMinimum(new BigDecimal("1")).withMaximum(new BigDecimal("232")).withAdvanced(true).withReadOnly(true).withRequired(true).withDescription("Sets the node ID<BR/>" + "The node ID is assigned by the controller and can not be changed.").withGroupName("thingcfg").build());
        return ConfigDescriptionBuilder.create(uri).withParameters(parameters).build();
    }
    ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart());
    Thing thing = getThing(thingUID);
    if (thing == null) {
        logger.debug("No thing found in getConfigDescription {}", uri);
        return null;
    }
    ThingUID bridgeUID = thing.getBridgeUID();
    if (bridgeUID == null) {
        logger.debug("No bridgeUID found in getConfigDescription {}", uri);
        return null;
    }
    // Get the controller for this thing
    Thing bridge = getThing(bridgeUID);
    if (bridge == null) {
        logger.debug("No bridge found in getConfigDescription {}", uri);
        return null;
    }
    final BigDecimal cfgNodeId = (BigDecimal) thing.getConfiguration().get(ZWaveBindingConstants.CONFIGURATION_NODEID);
    if (cfgNodeId == null) {
        logger.debug("No nodeId found in getConfigDescription {}", uri);
        return null;
    }
    int nodeId = cfgNodeId.intValue();
    // Get its handler and node
    ZWaveControllerHandler handler = (ZWaveControllerHandler) bridge.getHandler();
    if (handler == null) {
        logger.debug("NODE {}: No bridge handler found in getConfigDescription", nodeId);
        return null;
    }
    ZWaveNode node = handler.getNode(nodeId);
    if (node == null) {
        logger.debug("NODE {}: Node not found in getConfigDescription", nodeId);
        return null;
    }
    List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>();
    groups.add(ConfigDescriptionParameterGroupBuilder.create("actions").withLabel("Actions").withDescription("Actions").build());
    groups.add(ConfigDescriptionParameterGroupBuilder.create("thingcfg").withContext("home").withLabel("Device Configuration").withDescription("Device Configuration").build());
    List<ParameterOption> options = new ArrayList<ParameterOption>();
    options.add(new ParameterOption("600", "10 Minutes"));
    options.add(new ParameterOption("1800", "30 Minutes"));
    options.add(new ParameterOption("3600", "1 Hour"));
    options.add(new ParameterOption("7200", "2 Hours"));
    options.add(new ParameterOption("10800", "3 Hours"));
    options.add(new ParameterOption("21600", "6 Hours"));
    options.add(new ParameterOption("43200", "12 Hours"));
    options.add(new ParameterOption("86400", "1 Day"));
    options.add(new ParameterOption("172800", "2 Days"));
    options.add(new ParameterOption("864000", "10 Days"));
    parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_POLLPERIOD, Type.INTEGER).withLabel(ZWaveBindingConstants.CONFIG_BINDING_POLLINGPERIOD_LABEL).withDescription(ZWaveBindingConstants.CONFIG_BINDING_POLLINGPERIOD_DESC).withDefault("86400").withMinimum(new BigDecimal(15)).withMaximum(new BigDecimal(864000)).withOptions(options).withLimitToOptions(false).withGroupName("thingcfg").build());
    options = new ArrayList<ParameterOption>();
    options.add(new ParameterOption("0", "Disabled"));
    parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_CMDREPOLLPERIOD, Type.INTEGER).withLabel(ZWaveBindingConstants.CONFIG_BINDING_CMDREPOLLPERIOD_LABEL).withDescription(ZWaveBindingConstants.CONFIG_BINDING_CMDREPOLLPERIOD_DESC).withDefault("1500").withMinimum(new BigDecimal(100)).withMaximum(new BigDecimal(15000)).withOptions(options).withLimitToOptions(false).withGroupName("thingcfg").build());
    // If we support the wakeup class, then add the configuration
    ZWaveWakeUpCommandClass wakeupCmdClass = (ZWaveWakeUpCommandClass) node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_WAKE_UP);
    if (wakeupCmdClass != null) {
        groups.add(ConfigDescriptionParameterGroupBuilder.create("wakeup").withContext("sleep").withLabel("Wakeup Configuration").withDescription("Configuration for wakeup parameters on battery devices").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_WAKEUPINTERVAL, Type.INTEGER).withLabel("Wakeup Interval").withMinimum(new BigDecimal(wakeupCmdClass.getMinInterval())).withMaximum(new BigDecimal(wakeupCmdClass.getMaxInterval())).withDescription("Sets the number of seconds that the device will wakeup<BR/>" + "Setting a shorter time will allow openHAB to configure the device more regularly, but may use more battery power.<BR>" + "<B>Note:</B> This setting does not impact device notifications such as alarms.").withGroupName("wakeup").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_WAKEUPNODE, Type.INTEGER).withLabel("Wakeup Node").withAdvanced(true).withMinimum(new BigDecimal(1)).withMaximum(new BigDecimal(232)).withDescription("Sets the wakeup node to which the device will send notifications.<BR/>" + "This should normally be set to the openHAB controller - " + "if it isn't, openHAB will not receive notifications when the device wakes up, " + "and will not be able to configure the device.").withGroupName("wakeup").build());
    }
    // If we support the node name class, then add the configuration
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_NODE_NAMING) != null) {
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODENAME, Type.TEXT).withLabel("Node Name").withDescription("Sets a string for the device name").withGroupName("thingcfg").build());
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_NODELOCATION, Type.TEXT).withDescription("Sets a string for the device location").withLabel("Node Location").withGroupName("thingcfg").build());
    }
    // If we support the switch_all class, then add the configuration
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_SWITCH_ALL) != null) {
        options = new ArrayList<ParameterOption>();
        options.add(new ParameterOption("0", "Exclude from All On and All Off groups"));
        options.add(new ParameterOption("1", "Include in All On group"));
        options.add(new ParameterOption("2", "Include in All Off group"));
        options.add(new ParameterOption("255", "Include in All On and All Off groups"));
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_SWITCHALLMODE, Type.INTEGER).withLabel("Switch All Mode").withDescription("Set the mode for the switch when receiving SWITCH ALL commands.").withDefault("0").withGroupName("thingcfg").withOptions(options).withLimitToOptions(true).build());
    }
    // If we support DOOR_LOCK - add options
    if (node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_DOOR_LOCK) != null) {
        parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_DOORLOCKTIMEOUT, Type.INTEGER).withLabel("Lock Timeout").withDescription("Set the timeout on the lock.").withDefault("30").withGroupName("thingcfg").build());
    }
    ZWaveUserCodeCommandClass userCodeClass = (ZWaveUserCodeCommandClass) node.getCommandClass(ZWaveCommandClass.CommandClass.COMMAND_CLASS_USER_CODE);
    if (userCodeClass != null && userCodeClass.getNumberOfSupportedCodes() > 0) {
        groups.add(ConfigDescriptionParameterGroupBuilder.create("usercode").withContext("lock").withLabel("User Code").withDescription("Define the user codes for locks").build());
        for (int code = 1; code <= userCodeClass.getNumberOfSupportedCodes(); code++) {
            UserCode userCode = userCodeClass.getCachedUserCode(code);
            boolean readOnly = false;
            if (userCode != null) {
                readOnly = userCode.getState() == UserIdStatusType.RESERVED_BY_ADMINISTRATOR;
            }
            parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_USERCODE_LABEL + code, Type.TEXT).withLabel("Code " + code + " Label").withDescription("Name for user code " + code).withGroupName("usercode").build());
            parameters.add(ConfigDescriptionParameterBuilder.create(ZWaveBindingConstants.CONFIGURATION_USERCODE_CODE + code, Type.TEXT).withLabel("Code " + code).withDescription("Set the user code (4 to 10 numbers)").withReadOnly(readOnly).withGroupName("usercode").build());
        }
    }
    // If we're FAILED, allow removing from the controller
    // if (node.getNodeState() == ZWaveNodeState.FAILED) {
    parameters.add(ConfigDescriptionParameterBuilder.create("action_remove", Type.BOOLEAN).withLabel("Remove device from controller").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    // } else {
    // Otherwise, allow us to put this on the failed list
    parameters.add(ConfigDescriptionParameterBuilder.create("action_failed", Type.BOOLEAN).withLabel("Set device as FAILed").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    if (node.isInitializationComplete() == true) {
        parameters.add(ConfigDescriptionParameterBuilder.create("action_reinit", Type.BOOLEAN).withLabel("Reinitialise the device").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    }
    parameters.add(ConfigDescriptionParameterBuilder.create("action_heal", Type.BOOLEAN).withLabel("Heal the device").withAdvanced(true).withOptions(options).withDefault("false").withGroupName("actions").build());
    return ConfigDescriptionBuilder.create(uri).withParameters(parameters).withParameterGroups(groups).build();
}
Also used : ZWaveUserCodeCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveUserCodeCommandClass) ArrayList(java.util.ArrayList) UserCode(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveUserCodeCommandClass.UserCode) BigDecimal(java.math.BigDecimal) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass) ConfigDescriptionParameterGroup(org.openhab.core.config.core.ConfigDescriptionParameterGroup) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ParameterOption(org.openhab.core.config.core.ParameterOption) ThingUID(org.openhab.core.thing.ThingUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Thing(org.openhab.core.thing.Thing) ZWaveControllerHandler(org.openhab.binding.zwave.handler.ZWaveControllerHandler)

Example 4 with ThingTypeUID

use of org.openhab.core.thing.ThingTypeUID in project org.openhab.binding.zwave by openhab.

the class ZWaveProductTest method testVersion.

@Test
public void testVersion() {
    ZWaveProduct product = new ZWaveProduct(new ThingTypeUID("xx:yy"), 1, 2, 3, "1.2", "1.7");
    assertTrue(product.match(1, 2, 3, "1.2"));
    assertTrue(product.match(1, 2, 3, "1.5"));
    assertTrue(product.match(1, 2, 3, "1.7"));
    assertFalse(product.match(2, 2, 3, "1.5"));
    assertFalse(product.match(1, 3, 3, "1.5"));
    assertFalse(product.match(1, 2, 2, "1.5"));
    assertFalse(product.match(2, 2, 3, "1.1"));
    assertFalse(product.match(2, 2, 3, "1.11"));
}
Also used : ThingTypeUID(org.openhab.core.thing.ThingTypeUID) Test(org.junit.jupiter.api.Test)

Example 5 with ThingTypeUID

use of org.openhab.core.thing.ThingTypeUID in project org.openhab.binding.zwave by openhab.

the class ZWaveProductTest method testNoVersion.

@Test
public void testNoVersion() {
    ZWaveProduct product = new ZWaveProduct(new ThingTypeUID("xx:yy"), 1, 2, 3, null, null);
    assertTrue(product.match(1, 2, 3, "0.0"));
    assertTrue(product.match(1, 2, 3, "99.5"));
    assertTrue(product.match(1, 2, 3, "255.255"));
}
Also used : ThingTypeUID(org.openhab.core.thing.ThingTypeUID) Test(org.junit.jupiter.api.Test)

Aggregations

ThingTypeUID (org.openhab.core.thing.ThingTypeUID)303 ThingUID (org.openhab.core.thing.ThingUID)146 Nullable (org.eclipse.jdt.annotation.Nullable)94 Test (org.junit.jupiter.api.Test)77 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)68 HashMap (java.util.HashMap)61 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)61 Thing (org.openhab.core.thing.Thing)50 Bridge (org.openhab.core.thing.Bridge)29 ThingType (org.openhab.core.thing.type.ThingType)21 Configuration (org.openhab.core.config.core.Configuration)19 ThingHandler (org.openhab.core.thing.binding.ThingHandler)16 Hashtable (java.util.Hashtable)15 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)13 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 LinkedHashMap (java.util.LinkedHashMap)10 Locale (java.util.Locale)10 ChannelUID (org.openhab.core.thing.ChannelUID)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9