]> git.basschouten.com Git - openhab-addons.git/blob
85cae24597ffd92a24d35fb473a572081dd7e3b3
[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.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         return new SimpleCommand(command);
45     }
46
47     /**
48      * Return a ParameterizedCommand of the type given in parameter and for the given zone.
49      *
50      * @param command
51      * @param zone
52      * @return
53      */
54     public static SimpleCommand getIpControlCommand(SimpleCommandType command, int zone) {
55         return new SimpleCommand(command, zone);
56     }
57
58     /**
59      * Return a ParameterizedCommand of the type given in parameter. The
60      * parameter of the command has to be set before send.
61      *
62      * @param command
63      * @return
64      */
65     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command) {
66         return new ParameterizedCommand(command);
67     }
68
69     /**
70      * Return a ParameterizedCommand of the type given in parameter. The
71      * parameter of the command has to be set before send.
72      *
73      * @param command
74      * @param zone
75      * @return
76      */
77     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, int zone) {
78         return new ParameterizedCommand(command, zone);
79     }
80
81     /**
82      * Return a ParameterizedCommand of the type given in parameter. The
83      * parameter of the command is set with the given parameter value.
84      *
85      * @param command
86      * @param parameter
87      * @return
88      */
89     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter) {
90         ParameterizedCommand result = getIpControlCommand(command);
91         result.setParameter(parameter);
92         return result;
93     }
94
95     /**
96      * Return a ParameterizedCommand of the type given in parameter. The
97      * parameter of the command is set with the given parameter value.
98      *
99      * @param command
100      * @param parameter
101      * @param zone
102      * @return
103      */
104     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter,
105             int zone) {
106         ParameterizedCommand result = getIpControlCommand(command, zone);
107         result.setParameter(parameter);
108         return result;
109     }
110
111     /**
112      * Return an IpControlResponse object based on the given response data.
113      *
114      * @param responseData
115      * @return
116      */
117     public static Response getIpControlResponse(String responseData) {
118         return new Response(responseData);
119     }
120 }