]> git.basschouten.com Git - openhab-addons.git/blob
73df39b31a0e5935930c8fd472f1f4408fcc4926
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.automation.pwm.internal.type;
14
15 import static org.openhab.automation.pwm.internal.PWMConstants.*;
16
17 import java.math.BigDecimal;
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Set;
22
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;
32
33 /**
34  * Creates the configuration for the Trigger module in the rules engine.
35  *
36  * @author Fabian Wolter - Initial Contribution
37  */
38 @NonNullByDefault
39 public class PWMTriggerType extends TriggerType {
40     public static final String UID = PWMTriggerHandler.MODULE_TYPE_ID;
41
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)")
49                 .build());
50         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_PERIOD, Type.DECIMAL) //
51                 .withRequired(true) //
52                 .withMultiple(false) //
53                 .withDefault("600") //
54                 .withLabel("PWM Interval") //
55                 .withUnit("s") //
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)) //
62                 .withDefault("0") //
63                 .withLabel("Min Dutycycle") //
64                 .withUnit("%") //
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)")
72                 .build());
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") //
79                 .withUnit("%") //
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)")
88                 .build());
89         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
90                 .withRequired(false) //
91                 .withMultiple(false) //
92                 .withMinimum(BigDecimal.ZERO) //
93                 .withDefault("") //
94                 .withLabel("Dead Man Switch") //
95                 .withUnit("ms") //
96                 .withDescription(
97                         "If the duty cycle Item is not updated within this time (in ms), the output is switched off")
98                 .build());
99
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));
102
103         return new PWMTriggerType(configDescriptions, outputs);
104     }
105
106     public PWMTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
107         super(UID, configDescriptions, "PWM triggers", null, null, Visibility.VISIBLE, outputs);
108     }
109 }