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.List;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.automation.pwm.internal.handler.PWMTriggerHandler;
24 import org.openhab.core.automation.Visibility;
25 import org.openhab.core.automation.type.Output;
26 import org.openhab.core.automation.type.TriggerType;
27 import org.openhab.core.config.core.ConfigDescriptionParameter;
28 import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
29 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
30 import org.openhab.core.library.types.OnOffType;
33 * Creates the configuration for the Trigger module in the rules engine.
35 * @author Fabian Wolter - Initial Contribution
38 public class PWMTriggerType extends TriggerType {
39 public static final String UID = PWMTriggerHandler.MODULE_TYPE_ID;
41 public static PWMTriggerType initialize() {
42 List<ConfigDescriptionParameter> configDescriptions = new ArrayList<>();
43 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DUTY_CYCLE_ITEM, Type.TEXT) //
44 .withRequired(true) //
45 .withMultiple(false) //
46 .withContext("item") //
47 .withLabel("Dutycycle Item").withDescription("Item to read the current dutycycle from (PercentType)")
49 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_PERIOD, Type.DECIMAL) //
50 .withRequired(true) //
51 .withMultiple(false) //
52 .withDefault("600") //
53 .withLabel("PWM Interval") //
55 .withDescription("Duration of the PWM interval in sec.").build());
56 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MIN_DUTYCYCLE, Type.DECIMAL) //
57 .withRequired(false) //
58 .withMultiple(false) //
59 .withMinimum(BigDecimal.ZERO) //
60 .withMaximum(BigDecimal.valueOf(100)) //
62 .withLabel("Min Dutycycle") //
64 .withDescription("The dutycycle below this value will be increased to this value").build());
65 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MIN_TO_ZERO, Type.BOOLEAN) //
66 .withRequired(false) //
67 .withMultiple(false) //
68 .withDefault("false") //
69 .withLabel("Equate Min Dutycycle to 0") //
70 .withDescription("True if the dutycycle below Min Dutycycle should be set to 0 (defaults to false)")
72 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MAX_DUTYCYCLE, Type.DECIMAL) //
73 .withRequired(false) //
74 .withMultiple(false) //
75 .withMinimum(BigDecimal.ZERO) //
76 .withMaximum(BigDecimal.valueOf(100)) //
77 .withDefault("100") //
79 .withLabel("Max Dutycycle") //
80 .withDescription("The dutycycle above this value will be increased to 100").build());
81 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MAX_TO_HUNDRED, Type.BOOLEAN) //
82 .withRequired(false) //
83 .withMultiple(false) //
84 .withDefault("true") //
85 .withLabel("Equate Max Dutycycle to 100") //
86 .withDescription("True if the dutycycle above Max Dutycycle should be set to 100 (defaults to true)")
88 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
89 .withRequired(false) //
90 .withMultiple(false) //
91 .withMinimum(BigDecimal.ZERO) //
93 .withLabel("Dead Man Switch") //
96 "If the duty cycle Item is not updated within this time (in ms), the output is switched off")
99 List<Output> outputs = List.of(new Output(OUTPUT, OnOffType.class.getName(), "Output",
100 "Output value of the PWM module", Set.of("command"), null, null));
102 return new PWMTriggerType(configDescriptions, outputs);
105 public PWMTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
106 super(UID, configDescriptions, "PWM triggers", null, null, Visibility.VISIBLE, outputs);