2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.doorbird.internal.api;
15 import java.util.ArrayList;
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;
23 import com.google.gson.JsonSyntaxException;
26 * The {@link DoorbirdInfo} holds information about the Doorbird.
28 * @author Mark Hilbush - Initial contribution
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<>();
41 @SuppressWarnings("null")
42 public DoorbirdInfo(String infoJson) throws JsonSyntaxException {
43 DoorbirdInfoDTO info = DoorbirdAPI.fromJson(infoJson, DoorbirdInfoDTO.class);
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) {
56 String[] parts = relay.split("@");
57 if (parts.length == 2) {
58 controllerId = parts[0];
65 public @Nullable String getReturnCode() {
69 public @Nullable String getFirmwareVersion() {
70 return firmwareVersion;
73 public @Nullable String getBuildNumber() {
77 public @Nullable String getPrimaryMacAddress() {
78 return primaryMacAddress;
81 public @Nullable String getWifiMacAddress() {
82 return wifiMacAddress;
85 public @Nullable String getDeviceType() {
89 public @Nullable String getControllerId() {
93 public ArrayList<String> getRelays() {
97 public void addRelay(String relay) {