]> git.basschouten.com Git - openhab-addons.git/blob
8078b66191faf8ba07f4daff8e609df8de1f5a37
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lutron.internal.protocol.leap;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.lutron.internal.protocol.FanSpeedType;
17
18 /**
19  * Contains static methods for constructing LEAP messages
20  *
21  * @author Bob Adair - Initial contribution
22  */
23 @NonNullByDefault
24 public class Request {
25     public static final String BUTTON_GROUP_URL = "/buttongroup";
26
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);
32     }
33
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);
41     }
42
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);
50     }
51
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());
58     }
59
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());
65     }
66
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());
72     }
73
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());
79     }
80
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);
84     }
85
86     public static String ping() {
87         return request(CommuniqueType.READREQUEST, "/server/1/status/ping");
88     }
89
90     public static String getDevices() {
91         return request(CommuniqueType.READREQUEST, "/device");
92     }
93
94     public static String getVirtualButtons() {
95         return request(CommuniqueType.READREQUEST, "/virtualbutton");
96     }
97
98     public static String getButtonGroups() {
99         return request(CommuniqueType.READREQUEST, BUTTON_GROUP_URL);
100     }
101
102     public static String getAreas() {
103         return request(CommuniqueType.READREQUEST, "/area");
104     }
105
106     public static String getOccupancyGroups() {
107         return request(CommuniqueType.READREQUEST, "/occupancygroup");
108     }
109
110     public static String getZoneStatus(int zone) {
111         return request(CommuniqueType.READREQUEST, String.format("/zone/%d/status", zone));
112     }
113
114     public static String getOccupancyGroupStatus() {
115         return request(CommuniqueType.READREQUEST, "/occupancygroup/status");
116     }
117
118     public static String subscribeOccupancyGroupStatus() {
119         return request(CommuniqueType.SUBSCRIBEREQUEST, "/occupancygroup/status");
120     }
121 }