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