]> git.basschouten.com Git - openhab-addons.git/blob
4ee0957f055fc0e132a6c4024f553c8ea9f4d955
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.comfoair.internal;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Class to encapsulate all data which is needed to send a cmd to comfoair
23  *
24  * @author Holger Hees - Initial Contribution
25  * @author Hans Böhm - Refactoring
26  */
27 @NonNullByDefault
28 public class ComfoAirCommand {
29
30     private final List<String> keys;
31     private @Nullable Integer requestCmd;
32     private @Nullable Integer replyCmd;
33     private int[] requestData;
34     private final @Nullable Integer requestValue;
35     private final @Nullable Integer dataPosition;
36
37     /**
38      * @param key
39      *            command key
40      * @param requestCmd
41      *            command as byte value
42      * @param replyCmd
43      *            reply command as byte value
44      * @param data
45      *            request byte values
46      * @param requestValue
47      *            request byte value
48      * @param dataPosition
49      *            request byte position
50      */
51
52     public ComfoAirCommand(String key, @Nullable Integer requestCmd, @Nullable Integer replyCmd, int[] data,
53             @Nullable Integer dataPosition, @Nullable Integer requestValue) {
54         this.keys = new ArrayList<String>();
55         this.keys.add(key);
56         this.requestCmd = requestCmd;
57         this.replyCmd = replyCmd;
58         this.requestData = data;
59         this.dataPosition = dataPosition;
60         this.requestValue = requestValue;
61     }
62
63     /*
64      * Constructor for basic read command
65      */
66     public ComfoAirCommand(String key) {
67         this.keys = new ArrayList<String>();
68         this.keys.add(key);
69         ComfoAirCommandType commandType = ComfoAirCommandType.getCommandTypeByKey(key);
70         if (commandType != null) {
71             this.requestCmd = commandType.getReadCommand() == 0 ? null : commandType.getReadCommand();
72             this.replyCmd = commandType.getReadReplyCommand();
73         }
74         this.requestData = ComfoAirCommandType.Constants.EMPTY_INT_ARRAY;
75         this.dataPosition = null;
76         this.requestValue = null;
77     }
78
79     /**
80      * @param key
81      *            additional command key
82      */
83     public void addKey(String key) {
84         keys.add(key);
85     }
86
87     /**
88      * @return command keys
89      */
90     public List<String> getKeys() {
91         return keys;
92     }
93
94     /**
95      * @return command byte value
96      */
97     public @Nullable Integer getRequestCmd() {
98         return requestCmd;
99     }
100
101     /**
102      * @return request data as byte values
103      */
104     public int[] getRequestData() {
105         return requestData;
106     }
107
108     /**
109      * @return acknowledge cmd byte value
110      */
111     public @Nullable Integer getReplyCmd() {
112         return replyCmd;
113     }
114
115     /**
116      * @return request value as byte value
117      */
118     public @Nullable Integer getRequestValue() {
119         return requestValue;
120     }
121
122     /**
123      * @return position of request byte
124      */
125     public @Nullable Integer getDataPosition() {
126         return dataPosition;
127     }
128
129     /**
130      * set request command byte value
131      */
132     public void setRequestCmd(@Nullable Integer newRequestCmd) {
133         requestCmd = newRequestCmd;
134     }
135
136     /**
137      * set reply command byte value
138      */
139     public void setReplyCmd(@Nullable Integer newReplyCmd) {
140         replyCmd = newReplyCmd;
141     }
142
143     /**
144      * set request data byte values
145      */
146     public void setRequestData(int[] newRequestData) {
147         requestData = newRequestData;
148     }
149 }