]> git.basschouten.com Git - openhab-addons.git/blob
b7e94d313d6081ce93c80e110193760880c3fb23
[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.elerotransmitterstick.internal.stick;
14
15 import java.util.Arrays;
16
17 /**
18  * @author Volker Bier - Initial contribution
19  */
20 public class Response {
21     private ResponseStatus status;
22     private int[] channels;
23
24     public Response(ResponseStatus status, int[] channels) {
25         this.status = status;
26         this.channels = channels;
27     }
28
29     public Response(int[] channels) {
30         this.channels = channels;
31     }
32
33     public boolean isMoving() {
34         return status == ResponseStatus.MOVING_DOWN || status == ResponseStatus.MOVING_UP;
35     }
36
37     public int[] getChannelIds() {
38         return channels;
39     }
40
41     public boolean hasStatus() {
42         return status != null;
43     }
44
45     public ResponseStatus getStatus() {
46         return status;
47     }
48
49     public boolean isResponseFor(CommandPacket cmd) {
50         if (cmd == null || cmd.isEasyCheck()) {
51             return false;
52         }
53
54         byte[] cmdBytes = cmd.getBytes();
55         int[] cmdChannels = ResponseUtil.getChannelIds(cmdBytes[3], cmdBytes[4]);
56         return Arrays.equals(channels, cmdChannels);
57     }
58
59     @Override
60     public String toString() {
61         return status + " for channels " + Arrays.toString(channels);
62     }
63 }