]> git.basschouten.com Git - openhab-addons.git/blob
130df2b48c77b3e666eb1aa948db0464f0fbaed2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 ParameterizedCommand of the type given in parameter and for the given zone.
39      *
40      * @param command
41      * @param zone
42      * @return
43      */
44     public static SimpleCommand getIpControlCommand(SimpleCommandType command, int zone) {
45         SimpleCommand result = new SimpleCommand(command, zone);
46         return result;
47     }
48
49     /**
50      * Return a ParameterizedCommand of the type given in parameter. The
51      * parameter of the command has to be set before send.
52      *
53      * @param command
54      * @param zone
55      * @return
56      */
57     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, int zone) {
58         ParameterizedCommand result = new ParameterizedCommand(command, zone);
59         return result;
60     }
61
62     /**
63      * Return a ParameterizedCommand of the type given in parameter. The
64      * parameter of the command is set with the given paramter value.
65      *
66      * @param command
67      * @param parameter
68      * @param zone
69      * @return
70      */
71     public static ParameterizedCommand getIpControlCommand(ParameterizedCommandType command, String parameter,
72             int zone) {
73         ParameterizedCommand result = getIpControlCommand(command, zone);
74         result.setParameter(parameter);
75         return result;
76     }
77
78     /**
79      * Return a IpControlResponse object based on the given response data.
80      *
81      * @param responseData
82      * @return
83      */
84     public static Response getIpControlResponse(String responseData) {
85         return new Response(responseData);
86     }
87 }