]> git.basschouten.com Git - openhab-addons.git/blob
38cf6625ac4289a05d138bbfcb2aeafb7accd911
[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.binding.innogysmarthome.internal.client.entity.action;
14
15 import org.openhab.binding.innogysmarthome.internal.client.entity.capability.Capability;
16
17 /**
18  * Special {@link Action} needed to set a state of a device.
19  *
20  * @author Oliver Kuhl - Initial contribution
21  */
22 public class StateActionSetter extends Action {
23
24     private static final String CONSTANT = "Constant";
25
26     /**
27      * Constructs a new {@link StateActionSetter}.
28      *
29      * @param capabilityId String of the 32 character capability id
30      * @param capabilityType the type of the {@link Capability}, {@link Capability#TYPE_SWITCHACTUATOR} or
31      *            {@link Capability#TYPE_VARIABLEACTUATOR}
32      * @param state the new state as boolean (true=on, false=off)
33      */
34     public StateActionSetter(String capabilityId, String capabilityType, boolean state) {
35         setType(ACTION_TYPE_SETSTATE);
36         setTargetCapabilityById(capabilityId);
37         final ActionParams params = new ActionParams();
38
39         if (Capability.TYPE_SWITCHACTUATOR.equals(capabilityType)) {
40             params.setOnState(new BooleanActionParam(CONSTANT, state));
41         } else if (Capability.TYPE_VARIABLEACTUATOR.equals(capabilityType)) {
42             params.setValue(new BooleanActionParam(CONSTANT, state));
43         } else if (Capability.TYPE_ALARMACTUATOR.equals(capabilityType)) {
44             params.setOnState(new BooleanActionParam(CONSTANT, state));
45         }
46         setParams(params);
47     }
48
49     /**
50      * Constructs a new {@link StateActionSetter}.
51      *
52      * @param capabilityId String of the 32 character capability id
53      * @param capabilityType the type of the {@link Capability}, {@link Capability#TYPE_THERMOSTATACTUATOR}
54      * @param newValue the new double value
55      */
56     public StateActionSetter(String capabilityId, String capabilityType, double newValue) {
57         setType(ACTION_TYPE_SETSTATE);
58         setTargetCapabilityById(capabilityId);
59         final ActionParams params = new ActionParams();
60
61         if (Capability.TYPE_THERMOSTATACTUATOR.equals(capabilityType)) {
62             params.setPointTemperature(new DoubleActionParam(CONSTANT, newValue));
63         }
64         setParams(params);
65     }
66
67     /**
68      * Constructs a new {@link StateActionSetter}.
69      *
70      * @param capabilityId String of the 32 character capability id
71      * @param capabilityType the type of the {@link Capability}, {@link Capability#TYPE_DIMMERACTUATOR}
72      * @param newValue the new int value
73      */
74     public StateActionSetter(String capabilityId, String capabilityType, int newValue) {
75         setType(ACTION_TYPE_SETSTATE);
76         setTargetCapabilityById(capabilityId);
77         final ActionParams params = new ActionParams();
78
79         if (Capability.TYPE_DIMMERACTUATOR.equals(capabilityType)) {
80             params.setDimLevel(new IntegerActionParam(CONSTANT, newValue));
81         } else if (Capability.TYPE_ROLLERSHUTTERACTUATOR.equals(capabilityType)) {
82             params.setShutterLevel(new IntegerActionParam(CONSTANT, newValue));
83         }
84
85         setParams(params);
86     }
87
88     /**
89      * Constructs a new {@link StateActionSetter}.
90      *
91      * @param capabilityId String of the 32 character capability id
92      * @param capabilityType the type of the {@link Capability}, {@link Capability#TYPE_THERMOSTATACTUATOR}
93      * @param newValue the new string value
94      */
95     public StateActionSetter(String capabilityId, String capabilityType, String newValue) {
96         setType(ACTION_TYPE_SETSTATE);
97         setTargetCapabilityById(capabilityId);
98         final ActionParams params = new ActionParams();
99
100         if (Capability.TYPE_THERMOSTATACTUATOR.equals(capabilityType)) {
101             params.setOperationMode(new StringActionParam(CONSTANT, newValue));
102         }
103         setParams(params);
104     }
105 }