]> git.basschouten.com Git - openhab-addons.git/blob
f61df1b8ba1761e02aed7c45f1c96df8411cb4b4
[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 getDeviceDescription message and extracts the type and firmware version.
20  *
21  * @author Gerhard Riegler - Initial contribution
22  */
23 public class GetDeviceDescriptionParser extends CommonRpcParser<Object[], GetDeviceDescriptionParser> {
24     private String type;
25     private String firmware;
26     private String deviceInterface;
27
28     @SuppressWarnings("unchecked")
29     @Override
30     public GetDeviceDescriptionParser parse(Object[] message) throws IOException {
31         if (message != null && message.length > 0 && message[0] instanceof Map) {
32             Map<String, ?> mapMessage = (Map<String, ?>) message[0];
33             type = toString(mapMessage.get("TYPE"));
34             firmware = toString(mapMessage.get("FIRMWARE"));
35             deviceInterface = toString(mapMessage.get("INTERFACE"));
36         }
37         return this;
38     }
39
40     /**
41      * Returns the parsed type.
42      */
43     public String getType() {
44         return type;
45     }
46
47     /**
48      * Returns the parsed firmware version.
49      */
50     public String getFirmware() {
51         return firmware == null ? "" : firmware;
52     }
53
54     /**
55      * Returns the interface of the device.
56      */
57     public String getDeviceInterface() {
58         return deviceInterface;
59     }
60 }