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