]> git.basschouten.com Git - openhab-addons.git/blob
4ddb4af16a4a2ec4fa2fe1361d53beaffd50f861
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.pioneeravr.internal.protocol;
14
15 import org.openhab.binding.pioneeravr.internal.protocol.ParameterizedCommand.ParameterizedCommandType;
16 import org.openhab.binding.pioneeravr.internal.protocol.SimpleCommand.SimpleCommandType;
17 import org.openhab.binding.pioneeravr.internal.protocol.ip.IpAvrConnection;
18
19 /**
20  * Factory that allows to build IpControl commands/responses.
21  *
22  * @author Antoine Besnard - Initial contribution
23  */
24 public final class RequestResponseFactory {
25
26     /**
27      * Return a connection to the AVR with the given host and port.
28      *
29      * @param host
30      * @param port
31      * @return
32      */
33     public static IpAvrConnection getConnection(String host, Integer port) {
34         return new IpAvrConnection(host, port);
35     }
36
37     /**
38      * Return a SimpleCommand of the type given in parameter.
39      *
40      * @param command
41      * @return
42      */
43     public static SimpleCommand getIpControlCommand(SimpleCommandType command) {
44         SimpleCommand result = new SimpleCommand(command);
45         return result;
46     }
47
48     /**
49      * Return a ParameterizedCommand of the type given in parameter and for the given zone.
50      *
51      * @param command
52      * @param zone
53      * @return
54      */
55     public static SimpleCommand getIpControlCommand(SimpleCommandType command, int zone) {
56         SimpleCommand result = new SimpleCommand(command, zone);
57         return result;
58     }
59
60     /**
61      * Return a ParameterizedCommand of the type given in parameter. The
62      * parameter of the command has to be set before send.
63      *
64      * @param command
65      * @return
66      */
67     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command) {
68         ParameterizedCommand result = new ParameterizedCommand(command);
69         return result;
70     }
71
72     /**
73      * Return a ParameterizedCommand of the type given in parameter. The
74      * parameter of the command has to be set before send.
75      *
76      * @param command
77      * @param zone
78      * @return
79      */
80     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, int zone) {
81         ParameterizedCommand result = new ParameterizedCommand(command, zone);
82         return result;
83     }
84
85     /**
86      * Return a ParameterizedCommand of the type given in parameter. The
87      * parameter of the command is set with the given parameter value.
88      *
89      * @param command
90      * @param parameter
91      * @param zone
92      * @return
93      */
94     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter) {
95         ParameterizedCommand result = getIpControlCommand(command);
96         result.setParameter(parameter);
97         return result;
98     }
99
100     /**
101      * Return a ParameterizedCommand of the type given in parameter. The
102      * parameter of the command is set with the given parameter value.
103      *
104      * @param command
105      * @param parameter
106      * @param zone
107      * @return
108      */
109     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter,
110             int zone) {
111         ParameterizedCommand result = getIpControlCommand(command, zone);
112         result.setParameter(parameter);
113         return result;
114     }
115
116     /**
117      * Return an IpControlResponse object based on the given response data.
118      *
119      * @param responseData
120      * @return
121      */
122     public static Response getIpControlResponse(String responseData) {
123         return new Response(responseData);
124     }
125 }