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) {
28 String request = "{\"CommuniqueType\": \"CreateRequest\","
29 + "\"Header\": {\"Url\": \"/zone/%d/commandprocessor\"}," + "\"Body\": {" + "\"Command\": {"
30 + "\"CommandType\": \"GoToLevel\"," + "\"Parameter\": [{\"Type\": \"Level\", \"Value\": %d}]}}}";
31 return String.format(request, zone, value);
34 /** fadeTime must be in the format hh:mm:ss **/
35 public static String goToDimmedLevel(int zone, int value, String fadeTime) {
36 String request = "{\"CommuniqueType\": \"CreateRequest\","
37 + "\"Header\": {\"Url\": \"/zone/%d/commandprocessor\"},\"Body\": {\"Command\": {"
38 + "\"CommandType\": \"GoToDimmedLevel\","
39 + "\"DimmedLevelParameters\": {\"Level\": %d, \"FadeTime\": \"%s\"}}}}";
40 return String.format(request, zone, value, fadeTime);
43 /** fadeTime and delayTime must be in the format hh:mm:ss **/
44 public static String goToDimmedLevel(int zone, int value, String fadeTime, String delayTime) {
45 String request = "{\"CommuniqueType\": \"CreateRequest\","
46 + "\"Header\": {\"Url\": \"/zone/%d/commandprocessor\"},\"Body\": {\"Command\": {"
47 + "\"CommandType\": \"GoToDimmedLevel\","
48 + "\"DimmedLevelParameters\": {\"Level\": %d, \"FadeTime\": \"%s\", \"DelayTime\": \"%s\"}}}}";
49 return String.format(request, zone, value, fadeTime, delayTime);
52 public static String goToFanSpeed(int zone, FanSpeedType fanSpeed) {
53 String request = "{\"CommuniqueType\": \"CreateRequest\","
54 + "\"Header\": {\"Url\": \"/zone/%d/commandprocessor\"}," + "\"Body\": {"
55 + "\"Command\": {\"CommandType\": \"GoToFanSpeed\","
56 + "\"FanSpeedParameters\": {\"FanSpeed\": \"%s\"}}}}";
57 return String.format(request, zone, fanSpeed.leapValue());
60 public static String buttonCommand(int button, CommandType command) {
61 String request = "{\"CommuniqueType\": \"CreateRequest\","
62 + "\"Header\": {\"Url\": \"/button/%d/commandprocessor\"},"
63 + "\"Body\": {\"Command\": {\"CommandType\": \"%s\"}}}";
64 return String.format(request, button, command.toString());
67 public static String virtualButtonCommand(int virtualbutton, CommandType command) {
68 String request = "{\"CommuniqueType\": \"CreateRequest\","
69 + "\"Header\": {\"Url\": \"/virtualbutton/%d/commandprocessor\"},"
70 + "\"Body\": {\"Command\": {\"CommandType\": \"%s\"}}}";
71 return String.format(request, virtualbutton, command.toString());
74 public static String zoneCommand(int zone, CommandType commandType) {
75 String request = "{\"CommuniqueType\": \"CreateRequest\","
76 + "\"Header\": {\"Url\": \"/zone/%d/commandprocessor\"}," + "\"Body\": {" + "\"Command\": {"
77 + "\"CommandType\": \"%s\"}}}";
78 return String.format(request, zone, commandType.toString());
81 public static String request(CommuniqueType cType, String url) {
82 String request = "{\"CommuniqueType\": \"%s\",\"Header\": {\"Url\": \"%s\"}}";
83 return String.format(request, cType.toString(), url);
86 public static String ping() {
87 return request(CommuniqueType.READREQUEST, "/server/1/status/ping");
90 public static String getDevices() {
91 return request(CommuniqueType.READREQUEST, "/device");
94 public static String getVirtualButtons() {
95 return request(CommuniqueType.READREQUEST, "/virtualbutton");
98 public static String getButtonGroups() {
99 return request(CommuniqueType.READREQUEST, BUTTON_GROUP_URL);
102 public static String getAreas() {
103 return request(CommuniqueType.READREQUEST, "/area");
106 public static String getOccupancyGroups() {
107 return request(CommuniqueType.READREQUEST, "/occupancygroup");
110 public static String getZoneStatus(int zone) {
111 return request(CommuniqueType.READREQUEST, String.format("/zone/%d/status", zone));
114 public static String getOccupancyGroupStatus() {
115 return request(CommuniqueType.READREQUEST, "/occupancygroup/status");
118 public static String subscribeOccupancyGroupStatus() {
119 return request(CommuniqueType.SUBSCRIBEREQUEST, "/occupancygroup/status");