2 * Copyright (c) 2010-2023 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;
16 import java.util.Arrays;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO;
21 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO.DoorbirdInfoBha;
22 import org.openhab.binding.doorbird.internal.model.DoorbirdInfoDTO.DoorbirdInfoBha.DoorbirdInfoArray;
24 import com.google.gson.JsonSyntaxException;
27 * The {@link DoorbirdInfo} holds information about the Doorbird.
29 * @author Mark Hilbush - Initial contribution
32 public class DoorbirdInfo {
33 private @Nullable String returnCode;
34 private @Nullable String firmwareVersion;
35 private @Nullable String buildNumber;
36 private @Nullable String primaryMacAddress;
37 private @Nullable String wifiMacAddress;
38 private @Nullable String deviceType;
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 relays.addAll(Arrays.asList(doorbirdInfo.relays));
59 public @Nullable String getReturnCode() {
63 public @Nullable String getFirmwareVersion() {
64 return firmwareVersion;
67 public @Nullable String getBuildNumber() {
71 public @Nullable String getPrimaryMacAddress() {
72 return primaryMacAddress;
75 public @Nullable String getWifiMacAddress() {
76 return wifiMacAddress;
79 public @Nullable String getDeviceType() {
83 public @Nullable String getControllerId(@Nullable String configId) {
84 return relays.stream().map(relay -> relay.split("@")).filter(parts -> parts.length == 2).map(parts -> parts[0])
85 .filter(id -> configId == null || id.equals(configId)).reduce((first, second) -> second).orElse(null);
88 public ArrayList<String> getRelays() {