]> git.basschouten.com Git - openhab-addons.git/blob
445a6f3c415b3500bd95ee11a4927634e736ce06
[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.tr064.internal.soap;
14
15 import java.time.LocalDateTime;
16 import java.time.ZoneId;
17 import java.time.format.DateTimeFormatter;
18 import java.time.format.DateTimeParseException;
19 import java.util.Date;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.tr064.internal.dto.additions.Call;
24
25 /**
26  * The {@link CallListEntry} is used for post processing the retrieved call
27  * lists
28  *
29  * @author Jan N. Klug - Initial contribution
30  */
31 @NonNullByDefault
32 public class CallListEntry {
33     private static final DateTimeFormatter DATE_FORMAT_PARSER = DateTimeFormatter.ofPattern("dd.MM.yy HH:mm");
34     public @Nullable String localNumber;
35     public @Nullable String remoteNumber;
36     public @Nullable Date date;
37     public @Nullable Integer type;
38     public @Nullable Integer duration;
39
40     public CallListEntry(Call call) {
41         try {
42             date = Date.from(
43                     LocalDateTime.parse(call.getDate(), DATE_FORMAT_PARSER).atZone(ZoneId.systemDefault()).toInstant());
44         } catch (DateTimeParseException e) {
45             // ignore parsing error
46             date = null;
47         }
48         String[] durationParts = call.getDuration().split(":");
49         duration = Integer.parseInt(durationParts[0]) * 60 + Integer.parseInt(durationParts[1]);
50         type = Integer.parseInt(call.getType());
51         if (CallListType.OUTBOUND_COUNT.typeString().equals(call.getType())) {
52             localNumber = call.getCallerNumber();
53             remoteNumber = call.getCalled();
54         } else {
55             localNumber = call.getCalledNumber();
56             remoteNumber = call.getCaller();
57         }
58     }
59 }