2 * Copyright (c) 2010-2022 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 will be min this value").build());
66 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MAX_DUTYCYCLE, Type.DECIMAL) //
67 .withRequired(false) //
68 .withMultiple(false) //
69 .withMinimum(BigDecimal.ZERO) //
70 .withMaximum(BigDecimal.valueOf(100)) //
71 .withDefault("100") //
73 .withLabel("Max Dutycycle") //
74 .withDescription("The dutycycle will be max this value").build());
75 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
76 .withRequired(false) //
77 .withMultiple(false) //
78 .withMinimum(BigDecimal.ZERO) //
80 .withLabel("Dead Man Switch") //
83 "If the duty cycle Item is not updated within this time (in ms), the output is switched off")
86 List<Output> outputs = Collections.singletonList(new Output(OUTPUT, OnOffType.class.getName(), "Output",
87 "Output value of the PWM module", Set.of("command"), null, null));
89 return new PWMTriggerType(configDescriptions, outputs);
92 public PWMTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
93 super(UID, configDescriptions, "PWM triggers", null, null, Visibility.VISIBLE, outputs);