2 * Copyright (c) 2010-2024 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 getDevices("");
114 public static String getDevices(boolean thisDevice) {
115 String url = String.format("where=IsThisDevice:%s", (thisDevice) ? "true" : "false");
117 return getDevices(url);
120 public static String getDevices(String predicate) {
121 String url = "/device";
122 if (!predicate.isEmpty()) {
123 url = String.format("%s?%s", url, predicate);
126 return request(CommuniqueType.READREQUEST, url);
129 public static String getVirtualButtons() {
130 return request(CommuniqueType.READREQUEST, "/virtualbutton");
133 public static String getButtonGroups() {
134 return request(CommuniqueType.READREQUEST, BUTTON_GROUP_URL);
137 public static String getProject() {
138 return request(CommuniqueType.READREQUEST, "/project");
141 public static String getAreas() {
142 return request(CommuniqueType.READREQUEST, "/area");
145 public static String getOccupancyGroups() {
146 return request(CommuniqueType.READREQUEST, "/occupancygroup");
149 public static String getZoneStatus(int zone) {
150 return request(CommuniqueType.READREQUEST, String.format("/zone/%d/status", zone));
153 public static String getOccupancyGroupStatus() {
154 return request(CommuniqueType.READREQUEST, "/occupancygroup/status");
157 public static String subscribeOccupancyGroupStatus() {
158 return request(CommuniqueType.SUBSCRIBEREQUEST, "/occupancygroup/status");
161 public static String subscribeZoneStatus() {
162 return request(CommuniqueType.SUBSCRIBEREQUEST, "/zone/status");