]> git.basschouten.com Git - openhab-addons.git/blob
44054d56990707594c408da7ca7b9ddb38f1e0ae
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.pidcontroller.internal.type;
14
15 import static org.openhab.automation.pidcontroller.internal.PIDControllerConstants.*;
16
17 import java.math.BigDecimal;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.automation.pidcontroller.internal.handler.PIDControllerActionHandler;
22 import org.openhab.core.automation.Visibility;
23 import org.openhab.core.automation.type.ActionType;
24 import org.openhab.core.automation.type.Input;
25 import org.openhab.core.config.core.ConfigDescriptionParameter;
26 import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
27 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
28
29 /**
30  *
31  * @author Hilbrand Bouwkamp - Initial Contribution
32  */
33 @NonNullByDefault
34 public class PIDControllerActionType extends ActionType {
35     public static final String INPUT = "input";
36
37     public static PIDControllerActionType initialize() {
38         final ConfigDescriptionParameter outputItem = ConfigDescriptionParameterBuilder.create(OUTPUT, Type.TEXT)
39                 .withRequired(true).withMultiple(false).withContext("item").withLabel("Output Item")
40                 .withDescription("Item to send output").build();
41         final ConfigDescriptionParameter pInspectorItem = ConfigDescriptionParameterBuilder
42                 .create(P_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(false).withContext("item")
43                 .withLabel("P Inspector Item").withDescription("Item for debugging the P part").build();
44         final ConfigDescriptionParameter iInspectorItem = ConfigDescriptionParameterBuilder
45                 .create(I_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(false).withContext("item")
46                 .withLabel("I Inspector Item").withDescription("Item for debugging the I part").build();
47         final ConfigDescriptionParameter dInspectorItem = ConfigDescriptionParameterBuilder
48                 .create(D_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(false).withContext("item")
49                 .withLabel("D Inspector Item").withDescription("Item for debugging the D part").build();
50         final ConfigDescriptionParameter eInspectorItem = ConfigDescriptionParameterBuilder
51                 .create(E_INSPECTOR, Type.TEXT).withRequired(false).withMultiple(false).withContext("item")
52                 .withLabel("Error Inspector Item").withDescription("Item for debugging the error value").build();
53
54         List<ConfigDescriptionParameter> config = List.of(outputItem, pInspectorItem, iInspectorItem, dInspectorItem,
55                 eInspectorItem);
56
57         List<Input> inputs = List.of(createInput(INPUT), createInput(P_INSPECTOR), createInput(I_INSPECTOR),
58                 createInput(D_INSPECTOR), createInput(E_INSPECTOR));
59
60         return new PIDControllerActionType(config, inputs);
61     }
62
63     private static Input createInput(String name) {
64         return new Input(name, BigDecimal.class.getName());
65     }
66
67     public PIDControllerActionType(List<ConfigDescriptionParameter> configDescriptions, List<Input> inputs) {
68         super(PIDControllerActionHandler.MODULE_TYPE_ID, configDescriptions, "calculate PID output", null, null,
69                 Visibility.VISIBLE, inputs, null);
70     }
71 }