]> git.basschouten.com Git - openhab-addons.git/blob
4a8bd69cbf20db830ca5df69d21e4fe0eeff7023
[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.doorbird.internal.api;
14
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;
20
21 import com.google.gson.JsonSyntaxException;
22
23 /**
24  * The {@link SipStatus} holds SIP status information retrieved from the Doorbell
25  * that is used in the binding handler.
26  *
27  * @author Mark Hilbush - Initial contribution
28  */
29 @NonNullByDefault
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;
38
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;
54             }
55         }
56     }
57
58     public String getReturnCode() {
59         String value = returnCode;
60         return value != null ? value : "";
61     }
62
63     public String getSpeakerVolume() {
64         String value = speakerVolume;
65         return value != null ? value : "";
66     }
67
68     public String getMicrophoneVolume() {
69         String value = microphoneVolume;
70         return value != null ? value : "";
71     }
72
73     public String getLastErrorCode() {
74         String value = lastErrorCode;
75         return value != null ? value : "";
76     }
77
78     public String getLastErrorText() {
79         String value = lastErrorText;
80         return value != null ? value : "";
81     }
82
83     public String getRingTimeLimit() {
84         String value = ringTimeLimit;
85         return value != null ? value : "";
86     }
87
88     public String getCallTimeLimit() {
89         String value = callTimeLimit;
90         return value != null ? value : "";
91     }
92 }