]> git.basschouten.com Git - openhab-addons.git/blob
8791a6a178bd4dd34404dab8c759d300a033797a
[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.hydrawise.internal.api.local;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link HydrawiseZoneCommandBuilder} class builds a command URL string to use when sending commands to the
19  * Hydrawise local controller or cloud based API server
20  *
21  * @author Dan Cunningham - Initial contribution
22  *
23  */
24 @NonNullByDefault
25 class HydrawiseZoneCommandBuilder {
26
27     private final StringBuilder builder;
28
29     /**
30      * Construct a new {@link HydrawiseZoneCommandBuilder} class with a base URL
31      *
32      * @param baseURL
33      */
34     public HydrawiseZoneCommandBuilder(String baseURL) {
35         builder = new StringBuilder(baseURL);
36     }
37
38     /**
39      * Construct a new {@link HydrawiseZoneCommandBuilder} class with a base URL and API key.
40      *
41      * @param baseURL
42      * @param apiKey
43      */
44     public HydrawiseZoneCommandBuilder(String baseURL, String apiKey) {
45         this(baseURL);
46         builder.append("&api_key=" + apiKey);
47     }
48
49     /**
50      * Sets the action parameter
51      *
52      * @param action
53      * @return {@link HydrawiseZoneCommandBuilder}
54      */
55     public HydrawiseZoneCommandBuilder action(String action) {
56         builder.append("&action=" + action);
57         return this;
58     }
59
60     /**
61      * Sets the relayId parameter
62      *
63      * @param action
64      * @return {@link HydrawiseZoneCommandBuilder}
65      */
66     public HydrawiseZoneCommandBuilder relayId(int relayId) {
67         builder.append("&relay_id=" + relayId);
68         return this;
69     }
70
71     /**
72      * Sets the relay number parameter
73      *
74      * @param action
75      * @return {@link HydrawiseZoneCommandBuilder}
76      */
77     public HydrawiseZoneCommandBuilder relayNumber(int number) {
78         builder.append("&relay=" + number);
79         return this;
80     }
81
82     /**
83      * Sets the run duration parameter
84      *
85      * @param action
86      * @return {@link HydrawiseZoneCommandBuilder}
87      */
88     public HydrawiseZoneCommandBuilder duration(int seconds) {
89         builder.append("&custom=" + seconds);
90         return this;
91     }
92
93     /**
94      * Sets the controller Id parameter
95      *
96      * @param action
97      * @return {@link HydrawiseZoneCommandBuilder}
98      */
99     public HydrawiseZoneCommandBuilder controllerId(int controllerId) {
100         builder.append("&controller_id=" + controllerId);
101         return this;
102     }
103
104     @Override
105     public String toString() {
106         return builder.toString();
107     }
108 }