2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.livisismarthome.internal.client.api.entity.action;
15 import org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityDTO;
16 import org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityStateDTO;
19 * Special {@link ActionDTO} needed to set a state of a device.
21 * @author Oliver Kuhl - Initial contribution
23 public class StateActionSetterDTO extends ActionDTO {
25 private static final String CONSTANT = "Constant";
26 private static final String ACTION_TYPE_SETSTATE = "SetState";
29 * Constructs a new {@link StateActionSetterDTO}.
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)
36 public StateActionSetterDTO(String capabilityId, String capabilityType, boolean state) {
37 setType(ACTION_TYPE_SETSTATE);
38 setTargetCapabilityById(capabilityId);
39 final ActionParamsDTO params = new ActionParamsDTO();
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;
50 operationMode = CapabilityStateDTO.STATE_VALUE_OPERATION_MODE_AUTO;
52 operationMode = CapabilityStateDTO.STATE_VALUE_OPERATION_MODE_MANUAL;
54 params.setOperationMode(new StringActionParamDTO(CONSTANT, operationMode));
60 * Constructs a new {@link StateActionSetterDTO}.
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
66 public StateActionSetterDTO(String capabilityId, String capabilityType, double newValue) {
67 setType(ACTION_TYPE_SETSTATE);
68 setTargetCapabilityById(capabilityId);
69 final ActionParamsDTO params = new ActionParamsDTO();
71 if (CapabilityDTO.TYPE_THERMOSTATACTUATOR.equals(capabilityType)) {
72 params.setPointTemperature(new DoubleActionParamDTO(CONSTANT, newValue));
78 * Constructs a new {@link StateActionSetterDTO}.
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
84 public StateActionSetterDTO(String capabilityId, String capabilityType, int newValue) {
85 setType(ACTION_TYPE_SETSTATE);
86 setTargetCapabilityById(capabilityId);
87 final ActionParamsDTO params = new ActionParamsDTO();
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));