]> git.basschouten.com Git - openhab-addons.git/blob
b02c229bb713d44f8daf070e1a53696ad97fe82d
[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.List;
20 import java.util.Set;
21
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;
31
32 /**
33  * Creates the configuration for the Trigger module in the rules engine.
34  *
35  * @author Fabian Wolter - Initial Contribution
36  */
37 @NonNullByDefault
38 public class PWMTriggerType extends TriggerType {
39     public static final String UID = PWMTriggerHandler.MODULE_TYPE_ID;
40
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)")
48                 .build());
49         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_PERIOD, Type.DECIMAL) //
50                 .withRequired(true) //
51                 .withMultiple(false) //
52                 .withDefault("600") //
53                 .withLabel("PWM Interval") //
54                 .withUnit("s") //
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)) //
61                 .withDefault("0") //
62                 .withLabel("Min Dutycycle") //
63                 .withUnit("%") //
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)")
71                 .build());
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") //
78                 .withUnit("%") //
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)")
87                 .build());
88         configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
89                 .withRequired(false) //
90                 .withMultiple(false) //
91                 .withMinimum(BigDecimal.ZERO) //
92                 .withDefault("") //
93                 .withLabel("Dead Man Switch") //
94                 .withUnit("ms") //
95                 .withDescription(
96                         "If the duty cycle Item is not updated within this time (in ms), the output is switched off")
97                 .build());
98
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));
101
102         return new PWMTriggerType(configDescriptions, outputs);
103     }
104
105     public PWMTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
106         super(UID, configDescriptions, "PWM triggers", null, null, Visibility.VISIBLE, outputs);
107     }
108 }