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.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 public static final String CALL_TYPE_CALL = "CALL";
30 public static final String CALL_TYPE_CONNECT = "CONNECT";
31 public static final String CALL_TYPE_RING = "RING";
32 public static final String CALL_TYPE_DISCONNECT = "DISCONNECT";
34 private final String rawEvent;
35 private final String timestamp;
36 private final String callType;
37 private final String id;
38 private @Nullable String externalNo;
39 private @Nullable String internalNo;
40 private @Nullable String connectionType;
41 private @Nullable String line;
43 public CallEvent(String rawEvent) {
44 this.rawEvent = rawEvent;
46 String[] fields = rawEvent.split(";");
47 if (fields.length < 4) {
48 throw new IllegalArgumentException("Cannot parse call event: " + rawEvent);
51 timestamp = fields[0];
57 externalNo = fields[3];
58 internalNo = fields[4];
59 connectionType = fields[5];
61 case CALL_TYPE_CONNECT:
63 if (fields.length > 4) {
64 externalNo = fields[4];
66 externalNo = "Unknown";
71 internalNo = fields[4];
72 externalNo = fields[5];
73 connectionType = fields[6];
75 case CALL_TYPE_DISCONNECT:
79 throw new IllegalArgumentException("Invalid call type: " + callType);
83 public @Nullable String getLine() {
87 public String getTimestamp() {
91 public String getCallType() {
95 public String getId() {
99 public @Nullable String getExternalNo() {
103 public @Nullable String getInternalNo() {
107 public @Nullable String getConnectionType() {
108 return connectionType;
111 public String getRaw() {
116 public String toString() {
117 return "CallEvent [timestamp=" + timestamp + ", callType=" + callType + ", id=" + id + ", externalNo="
118 + externalNo + ", internalNo=" + internalNo + ", connectionType=" + connectionType + ", line=" + line