]> git.basschouten.com Git - openhab-addons.git/blob
953644f34480f398f09c4e9ee4e8b4f1177a95b4
[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.NonNull;
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 public class RDRepeaterResponse extends Response {
26
27     protected String repeaterLevel;
28
29     public RDRepeaterResponse(Response response) {
30         this(response.getPayload().length, 0, response.getPayload());
31     }
32
33     RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) {
34         super(dataLength, optionalDataLength, payload);
35
36         if (payload == null || payload.length < 3) {
37             return;
38         }
39
40         if (payload[1] == 0) {
41             repeaterLevel = REPEATERMODE_OFF;
42         } else if (payload[1] == 1 || payload[1] == 2) {
43             switch (payload[2]) {
44                 case 1:
45                     repeaterLevel = REPEATERMODE_LEVEL_1;
46                     break;
47                 case 2:
48                     repeaterLevel = REPEATERMODE_LEVEL_2;
49                     break;
50                 case 0:
51                     repeaterLevel = REPEATERMODE_OFF;
52                     break;
53                 default:
54                     return;
55             }
56
57             _isValid = true;
58         }
59     }
60
61     @NonNull
62     public StringType getRepeaterLevel() {
63         return StringType.valueOf(repeaterLevel);
64     }
65 }