]> git.basschouten.com Git - openhab-addons.git/blob
4aeb95c9d9bfd8d43afd39f5705b027b399b97d7
[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.homematic.internal.communicator.parser;
14
15 import java.io.IOException;
16 import java.util.Map;
17
18 /**
19  * Parses a listBidcosInterfaces message and extracts the type and gateway address.
20  *
21  * @author Gerhard Riegler - Initial contribution
22  */
23 public class ListBidcosInterfacesParser extends CommonRpcParser<Object[], ListBidcosInterfacesParser> {
24     private String type;
25     private String gatewayAddress;
26     private String firmware;
27     private Integer dutyCycleRatio;
28
29     @SuppressWarnings("unchecked")
30     @Override
31     public ListBidcosInterfacesParser parse(Object[] message) throws IOException {
32         if (message != null && message.length > 0) {
33             message = (Object[]) message[0];
34             for (int i = 0; i < message.length; i++) {
35                 Map<String, ?> mapMessage = (Map<String, ?>) message[i];
36                 boolean isDefault = toBoolean(mapMessage.get("DEFAULT"));
37
38                 if (isDefault) {
39                     type = toString(mapMessage.get("TYPE"));
40                     firmware = toString(mapMessage.get("FIRMWARE_VERSION"));
41                     gatewayAddress = getSanitizedAddress(mapMessage.get("ADDRESS"));
42                     dutyCycleRatio = toInteger(mapMessage.get("DUTY_CYCLE"));
43                 }
44             }
45         }
46         return this;
47     }
48
49     /**
50      * Returns the parsed type.
51      */
52     public String getType() {
53         return type == null ? "" : type;
54     }
55
56     /**
57      * Returns the parsed gateway address.
58      */
59     public String getGatewayAddress() {
60         return gatewayAddress;
61     }
62
63     /**
64      * Returns the firmware version.
65      */
66     public String getFirmware() {
67         return firmware == null ? "" : firmware;
68     }
69
70     /**
71      * Returns the duty cycle.
72      */
73     public Integer getDutyCycleRatio() {
74         return dutyCycleRatio;
75     }
76 }