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