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.avmfritz.internal.callmonitor;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * Call Events received from a fritzbox.
21 * 12.07.20 09:11:30;RING;0;0171123456;888888;SIP2;
22 * 12.07.20 09:13:40;DISCONNECT;0;0;
24 * @author Kai Kreuzer - Initial contribution
27 public class CallEvent {
29 private final String rawEvent;
30 private final String timestamp;
31 private final String callType;
32 private final String id;
33 private @Nullable String externalNo;
34 private @Nullable String internalNo;
35 private @Nullable String connectionType;
36 private @Nullable String line;
38 public CallEvent(String rawEvent) {
39 this.rawEvent = rawEvent;
41 String[] fields = rawEvent.split(";");
42 if (fields.length < 4) {
43 throw new IllegalArgumentException("Cannot parse call event: " + rawEvent);
46 timestamp = fields[0];
50 if (callType.equals("RING")) {
51 externalNo = fields[3];
52 internalNo = fields[4];
53 connectionType = fields[5];
54 } else if (callType.equals("CONNECT")) {
56 if (fields.length > 4) {
57 externalNo = fields[4];
59 externalNo = "Unknown";
61 } else if (callType.equals("CALL")) {
63 internalNo = fields[4];
64 externalNo = fields[5];
65 connectionType = fields[6];
66 } else if (callType.equals("DISCONNECT")) {
69 throw new IllegalArgumentException("Invalid call type: " + callType);
73 public @Nullable String getLine() {
77 public String getTimestamp() {
81 public String getCallType() {
85 public String getId() {
89 public @Nullable String getExternalNo() {
93 public @Nullable String getInternalNo() {
97 public @Nullable String getConnectionType() {
98 return connectionType;
101 public String getRaw() {
106 public String toString() {
107 return "CallEvent [timestamp=" + timestamp + ", callType=" + callType + ", id=" + id + ", externalNo="
108 + externalNo + ", internalNo=" + internalNo + ", connectionType=" + connectionType + ", line=" + line