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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.doorbird.internal.model.SipStatusDTO;
18 import org.openhab.binding.doorbird.internal.model.SipStatusDTO.SipStatusBha;
19 import org.openhab.binding.doorbird.internal.model.SipStatusDTO.SipStatusBha.SipStatusArray;
21 import com.google.gson.JsonSyntaxException;
24 * The {@link SipStatus} holds SIP status information retrieved from the Doorbell
25 * that is used in the binding handler.
27 * @author Mark Hilbush - Initial contribution
30 public class SipStatus {
31 private @Nullable String returnCode;
32 private @Nullable String speakerVolume;
33 private @Nullable String microphoneVolume;
34 private @Nullable String lastErrorCode;
35 private @Nullable String lastErrorText;
36 private @Nullable String ringTimeLimit;
37 private @Nullable String callTimeLimit;
39 @SuppressWarnings("null")
40 public SipStatus(String sipStatusJson) throws JsonSyntaxException {
41 SipStatusDTO sipStatus = DoorbirdAPI.fromJson(sipStatusJson, SipStatusDTO.class);
42 if (sipStatus != null) {
43 SipStatusBha bha = sipStatus.bha;
44 returnCode = bha.returnCode;
45 // SIP array should have only one entry
46 if (bha.sipStatusArray.length == 1) {
47 SipStatusArray sip = bha.sipStatusArray[0];
48 speakerVolume = sip.speakerVolume;
49 microphoneVolume = sip.microphoneVolume;
50 lastErrorCode = sip.lastErrorCode;
51 lastErrorText = sip.lastErrorText;
52 ringTimeLimit = sip.ringTimeLimit;
53 callTimeLimit = sip.callTimeLimit;
58 public String getReturnCode() {
59 String value = returnCode;
60 return value != null ? value : "";
63 public String getSpeakerVolume() {
64 String value = speakerVolume;
65 return value != null ? value : "";
68 public String getMicrophoneVolume() {
69 String value = microphoneVolume;
70 return value != null ? value : "";
73 public String getLastErrorCode() {
74 String value = lastErrorCode;
75 return value != null ? value : "";
78 public String getLastErrorText() {
79 String value = lastErrorText;
80 return value != null ? value : "";
83 public String getRingTimeLimit() {
84 String value = ringTimeLimit;
85 return value != null ? value : "";
88 public String getCallTimeLimit() {
89 String value = callTimeLimit;
90 return value != null ? value : "";