]> git.basschouten.com Git - openhab-addons.git/blob
d61ab7bfee64f5be99064c9ef77c17dd924d7b5a
[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.enocean.internal.messages.responses;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.enocean.internal.messages.Response;
19 import org.openhab.core.library.types.StringType;
20
21 /**
22  *
23  * @author Daniel Weber - Initial contribution
24  */
25 @NonNullByDefault
26 public class RDRepeaterResponse extends Response {
27
28     protected String repeaterLevel = "";
29
30     public RDRepeaterResponse(Response response) {
31         this(response.getPayload().length, 0, response.getPayload());
32     }
33
34     RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) {
35         super(dataLength, optionalDataLength, payload);
36
37         if (payload.length < 3) {
38             return;
39         }
40
41         if (payload[1] == 0) {
42             repeaterLevel = REPEATERMODE_OFF;
43         } else if (payload[1] == 1 || payload[1] == 2) {
44             switch (payload[2]) {
45                 case 1:
46                     repeaterLevel = REPEATERMODE_LEVEL_1;
47                     break;
48                 case 2:
49                     repeaterLevel = REPEATERMODE_LEVEL_2;
50                     break;
51                 case 0:
52                     repeaterLevel = REPEATERMODE_OFF;
53                     break;
54                 default:
55                     return;
56             }
57
58             isValid = true;
59         }
60     }
61
62     public StringType getRepeaterLevel() {
63         return StringType.valueOf(repeaterLevel);
64     }
65 }