2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.pwm.internal.type;
15 import static org.openhab.automation.pwm.internal.PWMConstants.*;
17 import java.math.BigDecimal;
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.openhab.automation.pwm.internal.handler.PWMTriggerHandler;
25 import org.openhab.core.automation.Visibility;
26 import org.openhab.core.automation.type.Output;
27 import org.openhab.core.automation.type.TriggerType;
28 import org.openhab.core.config.core.ConfigDescriptionParameter;
29 import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
30 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
31 import org.openhab.core.library.types.OnOffType;
34 * Creates the configuration for the Trigger module in the rules engine.
36 * @author Fabian Wolter - Initial Contribution
39 public class PWMTriggerType extends TriggerType {
40 public static final String UID = PWMTriggerHandler.MODULE_TYPE_ID;
42 public static PWMTriggerType initialize() {
43 List<ConfigDescriptionParameter> configDescriptions = new ArrayList<>();
44 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DUTY_CYCLE_ITEM, Type.TEXT) //
45 .withRequired(true) //
46 .withMultiple(false) //
47 .withContext("item") //
48 .withLabel("Dutycycle Item").withDescription("Item to read the current dutycycle from (PercentType)")
50 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_PERIOD, Type.DECIMAL) //
51 .withRequired(true) //
52 .withMultiple(false) //
53 .withDefault("600") //
54 .withLabel("PWM Interval") //
56 .withDescription("Duration of the PWM interval in sec.").build());
57 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MIN_DUTYCYCLE, Type.DECIMAL) //
58 .withRequired(false) //
59 .withMultiple(false) //
60 .withMinimum(BigDecimal.ZERO) //
61 .withMaximum(BigDecimal.valueOf(100)) //
63 .withLabel("Min Dutycycle") //
65 .withDescription("The dutycycle below this value will be increased to this value").build());
66 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MIN_TO_ZERO, Type.BOOLEAN) //
67 .withRequired(false) //
68 .withMultiple(false) //
69 .withDefault("false") //
70 .withLabel("Equate Min Dutycycle to 0") //
71 .withDescription("True if the dutycycle below Min Dutycycle should be set to 0 (defaults to false)")
73 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MAX_DUTYCYCLE, Type.DECIMAL) //
74 .withRequired(false) //
75 .withMultiple(false) //
76 .withMinimum(BigDecimal.ZERO) //
77 .withMaximum(BigDecimal.valueOf(100)) //
78 .withDefault("100") //
80 .withLabel("Max Dutycycle") //
81 .withDescription("The dutycycle above this value will be increased to 100").build());
82 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MAX_TO_HUNDRED, Type.BOOLEAN) //
83 .withRequired(false) //
84 .withMultiple(false) //
85 .withDefault("true") //
86 .withLabel("Equate Max Dutycycle to 100") //
87 .withDescription("True if the dutycycle above Max Dutycycle should be set to 100 (defaults to true)")
89 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
90 .withRequired(false) //
91 .withMultiple(false) //
92 .withMinimum(BigDecimal.ZERO) //
94 .withLabel("Dead Man Switch") //
97 "If the duty cycle Item is not updated within this time (in ms), the output is switched off")
100 List<Output> outputs = Collections.singletonList(new Output(OUTPUT, OnOffType.class.getName(), "Output",
101 "Output value of the PWM module", Set.of("command"), null, null));
103 return new PWMTriggerType(configDescriptions, outputs);
106 public PWMTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
107 super(UID, configDescriptions, "PWM triggers", null, null, Visibility.VISIBLE, outputs);