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.leap;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.lutron.internal.protocol.FanSpeedType;
19 * Contains static methods for constructing LEAP messages
21 * @author Bob Adair - Initial contribution
24 public class Request {
25 public static final String BUTTON_GROUP_URL = "/buttongroup";
27 public static String goToLevel(int zone, int value) {
29 {"CommuniqueType": "CreateRequest",\
30 "Header": {"Url": "/zone/%d/commandprocessor"},\
33 "CommandType": "GoToLevel",\
34 "Parameter": [{"Type": "Level", "Value": %d}]}}}\
36 return String.format(request, zone, value);
39 /** fadeTime must be in the format hh:mm:ss **/
40 public static String goToDimmedLevel(int zone, int value, String fadeTime) {
42 {"CommuniqueType": "CreateRequest",\
43 "Header": {"Url": "/zone/%d/commandprocessor"},"Body": {"Command": {\
44 "CommandType": "GoToDimmedLevel",\
45 "DimmedLevelParameters": {"Level": %d, "FadeTime": "%s"}}}}\
47 return String.format(request, zone, value, fadeTime);
50 /** fadeTime and delayTime must be in the format hh:mm:ss **/
51 public static String goToDimmedLevel(int zone, int value, String fadeTime, String delayTime) {
53 {"CommuniqueType": "CreateRequest",\
54 "Header": {"Url": "/zone/%d/commandprocessor"},"Body": {"Command": {\
55 "CommandType": "GoToDimmedLevel",\
56 "DimmedLevelParameters": {"Level": %d, "FadeTime": "%s", "DelayTime": "%s"}}}}\
58 return String.format(request, zone, value, fadeTime, delayTime);
61 public static String goToFanSpeed(int zone, FanSpeedType fanSpeed) {
63 {"CommuniqueType": "CreateRequest",\
64 "Header": {"Url": "/zone/%d/commandprocessor"},\
66 "Command": {"CommandType": "GoToFanSpeed",\
67 "FanSpeedParameters": {"FanSpeed": "%s"}}}}\
69 return String.format(request, zone, fanSpeed.leapValue());
72 public static String buttonCommand(int button, CommandType command) {
74 {"CommuniqueType": "CreateRequest",\
75 "Header": {"Url": "/button/%d/commandprocessor"},\
76 "Body": {"Command": {"CommandType": "%s"}}}\
78 return String.format(request, button, command.toString());
81 public static String virtualButtonCommand(int virtualbutton, CommandType command) {
83 {"CommuniqueType": "CreateRequest",\
84 "Header": {"Url": "/virtualbutton/%d/commandprocessor"},\
85 "Body": {"Command": {"CommandType": "%s"}}}\
87 return String.format(request, virtualbutton, command.toString());
90 public static String zoneCommand(int zone, CommandType commandType) {
92 {"CommuniqueType": "CreateRequest",\
93 "Header": {"Url": "/zone/%d/commandprocessor"},\
96 "CommandType": "%s"}}}\
98 return String.format(request, zone, commandType.toString());
101 public static String request(CommuniqueType cType, String url) {
102 String request = "{\"CommuniqueType\": \"%s\",\"Header\": {\"Url\": \"%s\"}}";
103 return String.format(request, cType.toString(), url);
106 public static String ping() {
107 return request(CommuniqueType.READREQUEST, "/server/1/status/ping");
110 public static String getDevices() {
111 return request(CommuniqueType.READREQUEST, "/device");
114 public static String getVirtualButtons() {
115 return request(CommuniqueType.READREQUEST, "/virtualbutton");
118 public static String getButtonGroups() {
119 return request(CommuniqueType.READREQUEST, BUTTON_GROUP_URL);
122 public static String getAreas() {
123 return request(CommuniqueType.READREQUEST, "/area");
126 public static String getOccupancyGroups() {
127 return request(CommuniqueType.READREQUEST, "/occupancygroup");
130 public static String getZoneStatus(int zone) {
131 return request(CommuniqueType.READREQUEST, String.format("/zone/%d/status", zone));
134 public static String getOccupancyGroupStatus() {
135 return request(CommuniqueType.READREQUEST, "/occupancygroup/status");
138 public static String subscribeOccupancyGroupStatus() {
139 return request(CommuniqueType.SUBSCRIBEREQUEST, "/occupancygroup/status");