Search in sources :

Example 1 with ConfigDescriptionParameter

use of org.openhab.core.config.core.ConfigDescriptionParameter 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 2 with ConfigDescriptionParameter

use of org.openhab.core.config.core.ConfigDescriptionParameter in project openhab-addons by openhab.

the class PIDControllerTriggerType method initialize.

public static PIDControllerTriggerType initialize() {
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<>();
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_INPUT_ITEM, Type.TEXT).withRequired(// 
    true).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "Input Item").withDescription(// 
    "Item to monitor").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_SETPOINT_ITEM, Type.TEXT).withRequired(// 
    true).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "Setpoint").withDescription(// 
    "Targeted setpoint").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_KP_GAIN, Type.DECIMAL).withRequired(true).withMultiple(// 
    false).withDefault(// 
    "1.0").withMinimum(// 
    BigDecimal.ZERO).withLabel(// 
    "Proportional Gain (Kp)").withDescription(// 
    "Change to output propertional to current error value.").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_KI_GAIN, Type.DECIMAL).withRequired(// 
    true).withMultiple(// 
    false).withDefault(// 
    "1.0").withMinimum(// 
    BigDecimal.ZERO).withLabel(// 
    "Integral Gain (Ki)").withDescription(// 
    "Accelerate movement towards the setpoint.").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_KD_GAIN, Type.DECIMAL).withRequired(// 
    true).withMultiple(// 
    false).withDefault(// 
    "1.0").withMinimum(// 
    BigDecimal.ZERO).withLabel(// 
    "Derivative Gain (Kd)").withDescription(// 
    "Slows the rate of change of the output.").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_KD_TIMECONSTANT, Type.DECIMAL).withRequired(// 
    true).withMultiple(// 
    false).withMinimum(// 
    BigDecimal.ZERO).withDefault(// 
    "1.0").withLabel(// 
    "Derivative Time Constant").withDescription(// 
    "Slows the rate of change of the D part (T1) in seconds.").withUnit(// 
    "s").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(CONFIG_LOOP_TIME, Type.DECIMAL).withRequired(// 
    true).withMultiple(// 
    false).withDefault(// 
    DEFAULT_LOOPTIME_MS).withLabel(// 
    "Loop Time").withDescription(// 
    "The interval the output value is updated in ms").withUnit(// 
    "ms").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(P_INSPECTOR, Type.TEXT).withRequired(// 
    false).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "P Inspector Item").withDescription(// 
    "Item for debugging the P part").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(I_INSPECTOR, Type.TEXT).withRequired(// 
    false).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "I Inspector Item").withDescription(// 
    "Item for debugging the I part").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(D_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "D Inspector Item").withDescription(// 
    "Item for debugging the D part").build());
    configDescriptions.add(// 
    ConfigDescriptionParameterBuilder.create(E_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(// 
    false).withContext(// 
    ITEM).withLabel(// 
    "Error Inspector Item").withDescription(// 
    "Item for debugging the error value").build());
    Output output = new Output(COMMAND, BigDecimal.class.getName(), "Output", "Output value of the PID Controller", Set.of("command"), null, null);
    return new PIDControllerTriggerType(configDescriptions, List.of(output));
}
Also used : Output(org.openhab.core.automation.type.Output) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) BigDecimal(java.math.BigDecimal)

Example 3 with ConfigDescriptionParameter

use of org.openhab.core.config.core.ConfigDescriptionParameter in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapper method mapEnrichedParameters.

/**
 * Maps configuration description parameters into enriched DTO objects.
 *
 * @param parameters the configuration description parameters (not null)
 * @return the parameter enriched DTO objects
 */
public static List<ConfigDescriptionParameterDTO> mapEnrichedParameters(List<ConfigDescriptionParameter> parameters) {
    List<ConfigDescriptionParameterDTO> configDescriptionParameterBeans = new ArrayList<>(parameters.size());
    for (ConfigDescriptionParameter configDescriptionParameter : parameters) {
        ConfigDescriptionParameterDTO configDescriptionParameterBean = new EnrichedConfigDescriptionParameterDTO(configDescriptionParameter.getName(), configDescriptionParameter.getType(), configDescriptionParameter.getMinimum(), configDescriptionParameter.getMaximum(), configDescriptionParameter.getStepSize(), configDescriptionParameter.getPattern(), configDescriptionParameter.isRequired(), configDescriptionParameter.isReadOnly(), configDescriptionParameter.isMultiple(), configDescriptionParameter.getContext(), configDescriptionParameter.getDefault(), configDescriptionParameter.getLabel(), configDescriptionParameter.getDescription(), mapOptions(configDescriptionParameter.getOptions()), mapFilterCriteria(configDescriptionParameter.getFilterCriteria()), configDescriptionParameter.getGroupName(), configDescriptionParameter.isAdvanced(), configDescriptionParameter.getLimitToOptions(), configDescriptionParameter.getMultipleLimit(), configDescriptionParameter.getUnit(), configDescriptionParameter.getUnitLabel(), configDescriptionParameter.isVerifyable());
        configDescriptionParameterBeans.add(configDescriptionParameterBean);
    }
    return configDescriptionParameterBeans;
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter)

Example 4 with ConfigDescriptionParameter

use of org.openhab.core.config.core.ConfigDescriptionParameter in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValuesAreAList.

@Test
public void testThatDefaultValuesAreAList() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withDefault(CONFIG_PARAMETER_DEFAULT_VALUE).withMultiple(true).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(notNullValue()));
    assertThat(ecdpdto.defaultValues, hasSize(3));
    assertThat(ecdpdto.defaultValues, is(equalTo(List.of("first value", "second value", "third value"))));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigDescriptionParameter

use of org.openhab.core.config.core.ConfigDescriptionParameter in project openhab-core by openhab.

the class ConfigDescriptionsTest method assertThatConfigDescriptionsOfFragmentHostAreLoadedProperly.

@Test
public void assertThatConfigDescriptionsOfFragmentHostAreLoadedProperly() throws Exception {
    bindingInstaller.exec(FRAGMENT_TEST_FRAGMENT_NAME, () -> {
        try {
            try (BundleCloseable bundle = new BundleCloseable(SyntheticBundleInstaller.install(bundleContext, FRAGMENT_TEST_HOST_NAME))) {
                assertThat(bundle, is(notNullValue()));
                Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
                ConfigDescription description = Objects.requireNonNull(findDescription(configDescriptions, "config:fragmentConfig"));
                List<ConfigDescriptionParameter> parameters = description.getParameters();
                assertThat(parameters.size(), is(1));
                ConfigDescriptionParameter usernameParameter = findParameter(description, "testParam");
                assertThat(usernameParameter, is(notNullValue()));
                assertThat(usernameParameter.getType(), is(Type.TEXT));
                assertThat(usernameParameter.getLabel(), is("Test"));
                assertThat(usernameParameter.isRequired(), is(false));
                assertThat(usernameParameter.isMultiple(), is(false));
                assertThat(usernameParameter.isReadOnly(), is(false));
                assertThat(usernameParameter.getDescription(), is("Test Parameter."));
            }
        } catch (Exception e) {
        // do nothing: handle exception
        }
    });
}
Also used : BundleCloseable(org.openhab.core.test.BundleCloseable) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Aggregations

ConfigDescriptionParameter (org.openhab.core.config.core.ConfigDescriptionParameter)56 Test (org.junit.jupiter.api.Test)27 ArrayList (java.util.ArrayList)17 ConfigDescription (org.openhab.core.config.core.ConfigDescription)17 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)11 URI (java.net.URI)10 Nullable (org.eclipse.jdt.annotation.Nullable)9 ParameterOption (org.openhab.core.config.core.ParameterOption)8 BigDecimal (java.math.BigDecimal)7 ConfigDescriptionParameterGroup (org.openhab.core.config.core.ConfigDescriptionParameterGroup)7 Configuration (org.openhab.core.config.core.Configuration)6 ActionType (org.openhab.core.automation.type.ActionType)5 JavaTest (org.openhab.core.test.java.JavaTest)5 Channel (org.openhab.core.thing.Channel)5 ZclLevelControlCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclLevelControlCluster)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Output (org.openhab.core.automation.type.Output)4 ConfigDescriptionParameterDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO)4 Collection (java.util.Collection)3