]> git.basschouten.com Git - openhab-addons.git/blob
338073b7f3ea97a3f3664f9e892244ca73fe585f
[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      * @param zone
88      * @return
89      */
90     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter) {
91         ParameterizedCommand result = getIpControlCommand(command);
92         result.setParameter(parameter);
93         return result;
94     }
95
96     /**
97      * Return a ParameterizedCommand of the type given in parameter. The
98      * parameter of the command is set with the given parameter value.
99      *
100      * @param command
101      * @param parameter
102      * @param zone
103      * @return
104      */
105     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter,
106             int zone) {
107         ParameterizedCommand result = getIpControlCommand(command, zone);
108         result.setParameter(parameter);
109         return result;
110     }
111
112     /**
113      * Return an IpControlResponse object based on the given response data.
114      *
115      * @param responseData
116      * @return
117      */
118     public static Response getIpControlResponse(String responseData) {
119         return new Response(responseData);
120     }
121 }