Search in sources :

Example 21 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class WelcomeHomeActionType method initialize.

public static WelcomeHomeActionType initialize() {
    final ConfigDescriptionParameter device = ConfigDescriptionParameterBuilder.create(CONFIG_DEVICE, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Device").withDescription("Device description").build();
    final ConfigDescriptionParameter result = ConfigDescriptionParameterBuilder.create(CONFIG_RESULT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Result").withDescription("Result description").build();
    List<ConfigDescriptionParameter> config = new ArrayList<ConfigDescriptionParameter>();
    config.add(device);
    config.add(result);
    return new WelcomeHomeActionType(config);
}
Also used : ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 22 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class WelcomeHomeRulesProvider method createLightsRule.

/**
 * This method creates a rule from scratch by using trigger, condition, action, configDescriptions and
 * configuration, tags.
 *
 * @return the created rule
 */
private Rule createLightsRule() {
    // initialize the trigger
    String triggerId = "LightsSwitchOnRuleTrigger";
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(new Trigger(triggerId, LightsTriggerType.UID, null));
    // initialize the condition - here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    Configuration config = new Configuration();
    config.put(StateConditionType.CONFIG_STATE, "on");
    List<Condition> conditions = new ArrayList<Condition>();
    Map<String, String> inputs = new HashMap<String, String>();
    inputs.put(StateConditionType.INPUT_CURRENT_STATE, triggerId + "." + StateConditionType.INPUT_CURRENT_STATE);
    conditions.add(new Condition("LightsStateCondition", StateConditionType.UID, config, inputs));
    // initialize the action - here the tricky part is the referring into the action configuration parameter - the
    // template configuration parameter. The syntax is a similar to the JUEL syntax.
    config = new Configuration();
    config.put(WelcomeHomeActionType.CONFIG_DEVICE, "Lights");
    config.put(WelcomeHomeActionType.CONFIG_RESULT, "Lights are switched on");
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action("LightsSwitchOnAction", WelcomeHomeActionType.UID, config, null));
    // initialize the configDescriptions
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    final ConfigDescriptionParameter device = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_UNIT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Device").withDescription("Device description").build();
    final ConfigDescriptionParameter result = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_EXPECTED_RESULT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Result").withDescription("Result description").build();
    configDescriptions.add(device);
    configDescriptions.add(result);
    // initialize the configuration
    config = new Configuration();
    config.put(CONFIG_UNIT, "Lights");
    config.put(CONFIG_EXPECTED_RESULT, "The lights are switched on.");
    // create the rule
    Rule lightsSwitchOn = new Rule(L_UID);
    lightsSwitchOn.setTriggers(triggers);
    lightsSwitchOn.setConfigurationDescriptions(configDescriptions);
    lightsSwitchOn.setConditions(conditions);
    lightsSwitchOn.setActions(actions);
    // initialize the tags
    Set<String> tags = new HashSet<String>();
    tags.add("lights");
    // set the tags
    lightsSwitchOn.setTags(tags);
    return lightsSwitchOn;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Trigger(org.eclipse.smarthome.automation.Trigger) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Rule(org.eclipse.smarthome.automation.Rule) HashSet(java.util.HashSet)

Example 23 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class ConfigI18nLocalizationService method getLocalizedConfigDescriptionParameter.

/**
 * Localize a config description parameter.
 *
 * @param bundle the bundle the i18n resources are located
 * @param configDescription the config description the parameter is part of
 * @param parameter the parameter that should be localized
 * @param locale the locale it should be localized to
 * @return a localized parameter on success, a non-localized one on error (e.g. no translation is found).
 */
public ConfigDescriptionParameter getLocalizedConfigDescriptionParameter(final Bundle bundle, final ConfigDescription configDescription, final ConfigDescriptionParameter parameter, @Nullable final Locale locale) {
    final URI configDescriptionURI = configDescription.getUID();
    final String parameterName = parameter.getName();
    final String label = this.configDescriptionParamI18nUtil.getParameterLabel(bundle, configDescriptionURI, parameterName, parameter.getLabel(), locale);
    final String description = this.configDescriptionParamI18nUtil.getParameterDescription(bundle, configDescriptionURI, parameterName, parameter.getDescription(), locale);
    final String pattern = this.configDescriptionParamI18nUtil.getParameterPattern(bundle, configDescriptionURI, parameterName, parameter.getPattern(), locale);
    final String unitLabel = this.configDescriptionParamI18nUtil.getParameterUnitLabel(bundle, configDescriptionURI, parameterName, parameter.getUnit(), parameter.getUnitLabel(), locale);
    final List<ParameterOption> options = getLocalizedOptions(parameter.getOptions(), bundle, configDescriptionURI, parameterName, locale);
    final ConfigDescriptionParameter localizedParameter = ConfigDescriptionParameterBuilder.create(parameterName, parameter.getType()).withMinimum(parameter.getMinimum()).withMaximum(parameter.getMaximum()).withStepSize(parameter.getStepSize()).withPattern(pattern).withRequired(parameter.isRequired()).withReadOnly(parameter.isReadOnly()).withMultiple(parameter.isMultiple()).withContext(parameter.getContext()).withDefault(parameter.getDefault()).withLabel(label).withDescription(description).withOptions(options).withFilterCriteria(parameter.getFilterCriteria()).withGroupName(parameter.getGroupName()).withAdvanced(parameter.isAdvanced()).withVerify(parameter.isVerifyable()).withLimitToOptions(parameter.getLimitToOptions()).withMultipleLimit(parameter.getMultipleLimit()).withUnit(parameter.getUnit()).withUnitLabel(unitLabel).build();
    return localizedParameter;
}
Also used : ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) URI(java.net.URI)

Example 24 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class ConfigDescriptionDTOMapper method mapParameters.

/**
 * Maps configuration description parameters into DTO objects.
 *
 * @param parameters the configuration description parameters (not null)
 * @return the parameter DTO objects (not null)
 */
public static List<ConfigDescriptionParameterDTO> mapParameters(List<ConfigDescriptionParameter> parameters) {
    List<ConfigDescriptionParameterDTO> configDescriptionParameterBeans = new ArrayList<>(parameters.size());
    for (ConfigDescriptionParameter configDescriptionParameter : parameters) {
        ConfigDescriptionParameterDTO configDescriptionParameterBean = new ConfigDescriptionParameterDTO(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 : ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 25 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class PersistentInbox method synchronizeConfiguration.

private boolean synchronizeConfiguration(ThingTypeUID thingTypeUID, Map<String, Object> properties, Configuration config) {
    boolean configUpdated = false;
    final Set<Map.Entry<String, Object>> propertySet = properties.entrySet();
    final ThingType thingType = thingTypeRegistry.getThingType(thingTypeUID);
    final List<ConfigDescriptionParameter> configDescParams = getConfigDescParams(thingType);
    for (Map.Entry<String, Object> propertyEntry : propertySet) {
        final String propertyKey = propertyEntry.getKey();
        final Object propertyValue = propertyEntry.getValue();
        // Check if the key is present in the configuration.
        if (!config.containsKey(propertyKey)) {
            continue;
        }
        // Normalize first
        ConfigDescriptionParameter configDescParam = getConfigDescriptionParam(configDescParams, propertyKey);
        Object normalizedValue = ConfigUtil.normalizeType(propertyValue, configDescParam);
        // If the value is equal to the one of the configuration, there is nothing to do.
        if (Objects.equals(normalizedValue, config.get(propertyKey))) {
            continue;
        }
        // - the given key is part of the configuration
        // - the values differ
        // update value
        config.put(propertyKey, normalizedValue);
        configUpdated = true;
    }
    return configUpdated;
}
Also used : ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)29 ArrayList (java.util.ArrayList)13 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)9 URI (java.net.URI)7 Configuration (org.eclipse.smarthome.config.core.Configuration)5 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)4 Test (org.junit.Test)4 Bundle (org.osgi.framework.Bundle)4 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Action (org.eclipse.smarthome.automation.Action)3 Condition (org.eclipse.smarthome.automation.Condition)3 Trigger (org.eclipse.smarthome.automation.Trigger)3 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 Rule (org.eclipse.smarthome.automation.Rule)2 Input (org.eclipse.smarthome.automation.type.Input)2