]> git.basschouten.com Git - openhab-addons.git/blob
902c806c3ddc44237bdaa1fe8d6601f0a9bf2c92
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.doorbird.internal.api;
14
15 import java.util.ArrayList;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO;
20 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO.DoorbirdInfoBha;
21 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO.DoorbirdInfoBha.DoorbirdInfoArray;
22
23 import com.google.gson.JsonSyntaxException;
24
25 /**
26  * The {@link DoorbirdInfo} holds information about the Doorbird.
27  *
28  * @author Mark Hilbush - Initial contribution
29  */
30 @NonNullByDefault
31 public class DoorbirdInfo {
32     private @Nullable String returnCode;
33     private @Nullable String firmwareVersion;
34     private @Nullable String buildNumber;
35     private @Nullable String primaryMacAddress;
36     private @Nullable String wifiMacAddress;
37     private @Nullable String deviceType;
38     private @Nullable String controllerId;
39     private ArrayList<String> relays = new ArrayList<>();
40
41     @SuppressWarnings("null")
42     public DoorbirdInfo(String infoJson) throws JsonSyntaxException {
43         DoorbirdInfoDTO info = DoorbirdAPI.fromJson(infoJson, DoorbirdInfoDTO.class);
44         if (info != null) {
45             DoorbirdInfoBha bha = info.bha;
46             returnCode = bha.returnCode;
47             if (bha.doorbirdInfoArray.length == 1) {
48                 DoorbirdInfoArray doorbirdInfo = bha.doorbirdInfoArray[0];
49                 firmwareVersion = doorbirdInfo.firmwareVersion;
50                 buildNumber = doorbirdInfo.buildNumber;
51                 primaryMacAddress = doorbirdInfo.primaryMacAddress;
52                 wifiMacAddress = doorbirdInfo.wifiMacAddress;
53                 deviceType = doorbirdInfo.deviceType;
54                 for (String relay : doorbirdInfo.relays) {
55                     relays.add(relay);
56                     String[] parts = relay.split("@");
57                     if (parts.length == 2) {
58                         controllerId = parts[0];
59                     }
60                 }
61             }
62         }
63     }
64
65     public @Nullable String getReturnCode() {
66         return returnCode;
67     }
68
69     public @Nullable String getFirmwareVersion() {
70         return firmwareVersion;
71     }
72
73     public @Nullable String getBuildNumber() {
74         return buildNumber;
75     }
76
77     public @Nullable String getPrimaryMacAddress() {
78         return primaryMacAddress;
79     }
80
81     public @Nullable String getWifiMacAddress() {
82         return wifiMacAddress;
83     }
84
85     public @Nullable String getDeviceType() {
86         return deviceType;
87     }
88
89     public @Nullable String getControllerId() {
90         return controllerId;
91     }
92
93     public ArrayList<String> getRelays() {
94         return relays;
95     }
96
97     public void addRelay(String relay) {
98         relays.add(relay);
99     }
100 }