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.lutron.internal.protocol;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lutron.internal.handler.LeapBridgeHandler;
18 import org.openhab.binding.lutron.internal.protocol.leap.CommandType;
19 import org.openhab.binding.lutron.internal.protocol.leap.LeapCommand;
20 import org.openhab.binding.lutron.internal.protocol.leap.Request;
21 import org.openhab.binding.lutron.internal.protocol.lip.LutronCommandType;
22 import org.openhab.binding.lutron.internal.protocol.lip.LutronOperation;
23 import org.openhab.binding.lutron.internal.protocol.lip.TargetType;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Lutron DEVICE command object
30 * @author Bob Adair - Initial contribution
33 public class DeviceCommand extends LutronCommandNew {
35 public static final Integer ACTION_PRESS = 3;
36 public static final Integer ACTION_RELEASE = 4;
37 public static final Integer ACTION_HOLD = 5;
38 public static final Integer ACTION_LED_STATE = 9;
39 public static final Integer LED_OFF = 0;
40 public static final Integer LED_ON = 1;
41 public static final Integer LED_FLASH = 2; // Same as 1 on RA2 keypads
42 public static final Integer LED_RAPIDFLASH = 3; // Same as 1 on RA2 keypads
44 // occupancy sensor defs
45 public static final String OCCUPIED_STATE_COMPONENT = "2";
46 public static final String STATE_OCCUPIED = "3";
47 public static final String STATE_UNOCCUPIED = "4";
49 private final Logger logger = LoggerFactory.getLogger(DeviceCommand.class);
51 private final Integer component;
52 private final @Nullable Integer leapComponent;
53 private final Integer action;
54 private final @Nullable Object parameter;
56 public DeviceCommand(TargetType targetType, LutronOperation operation, Integer integrationId, Integer component,
57 @Nullable Integer leapComponent, Integer action, @Nullable Object parameter) {
58 super(targetType, operation, LutronCommandType.DEVICE, integrationId);
60 this.component = component;
61 this.leapComponent = leapComponent;
62 this.parameter = parameter;
66 public String lipCommand() {
67 StringBuilder builder = new StringBuilder().append(operation).append(commandType);
68 builder.append(',').append(integrationId);
69 builder.append(',').append(component);
70 builder.append(',').append(action);
71 if (parameter != null) {
72 builder.append(',').append(parameter);
75 return builder.toString();
79 public @Nullable LeapCommand leapCommand(LeapBridgeHandler bridgeHandler, @Nullable Integer leapZone) {
80 if (targetType == TargetType.KEYPAD) {
81 if (leapComponent == null) {
82 logger.debug("Ignoring device command. No leap component in command.");
86 Integer integrationId = this.integrationId;
87 Integer leapComponent = this.leapComponent; // make the broken null checker happy
88 if (action.equals(DeviceCommand.ACTION_PRESS) && integrationId != null && leapComponent != null) {
89 int button = bridgeHandler.getButton(integrationId, leapComponent);
91 return new LeapCommand(Request.buttonCommand(button, CommandType.PRESSANDHOLD));
93 } else if (action.equals(DeviceCommand.ACTION_RELEASE) && integrationId != null && leapComponent != null) {
94 int button = bridgeHandler.getButton(integrationId, leapComponent);
96 return new LeapCommand(Request.buttonCommand(button, CommandType.RELEASE));
99 logger.debug("Ignoring device command with unsupported action.");
102 } else if (targetType == TargetType.VIRTUALKEYPAD) {
103 if (action.equals(DeviceCommand.ACTION_PRESS)) {
104 return new LeapCommand(Request.virtualButtonCommand(component, CommandType.PRESSANDRELEASE));
105 } else if (action.equals(DeviceCommand.ACTION_RELEASE)) {
106 logger.trace("Ignoring release command for virtual keypad button.");
109 logger.debug("Ignoring device command with unsupported action.");
113 logger.debug("Ignoring device command with unsupported target type.");
116 logger.debug("Ignoring unsupported device command.");
121 public String toString() {