]> git.basschouten.com Git - openhab-addons.git/blob
d6bf31f09bfce03c8220c65e6ca34525987c6b75
[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.mikrotik.internal.model;
14
15 import static org.openhab.binding.mikrotik.internal.model.RouterosDevice.PROP_ID_KEY;
16
17 import java.math.BigInteger;
18 import java.time.LocalDateTime;
19 import java.util.Map;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.mikrotik.internal.util.Converter;
24
25 /**
26  * The {@link RouterosRegistrationBase} is a base model class for WiFi client models having casting accessors for
27  * data that is same for all WiFi client types.
28  *
29  * @author Oleg Vivtash - Initial contribution
30  */
31 @NonNullByDefault
32 public class RouterosRegistrationBase extends RouterosBaseData {
33
34     public RouterosRegistrationBase(Map<String, String> props) {
35         super(props);
36         this.postProcess();
37     }
38
39     protected void postProcess() {
40         if (hasProp("bytes")) {
41             String bytesStr = getProp("bytes");
42             if (bytesStr != null) {
43                 String[] bytes = bytesStr.split(",");
44                 setProp("tx-byte", bytes[0]);
45                 setProp("rx-byte", bytes[1]);
46             }
47         }
48         if (hasProp("packets")) {
49             String packetsStr = getProp("packets");
50             if (packetsStr != null) {
51                 String[] packets = packetsStr.split(",");
52                 setProp("tx-packet", packets[0]);
53                 setProp("rx-packet", packets[1]);
54             }
55         }
56     }
57
58     public @Nullable String getId() {
59         return getProp(PROP_ID_KEY);
60     }
61
62     public @Nullable String getName() {
63         return getProp("name");
64     }
65
66     public @Nullable String getComment() {
67         return getProp("comment");
68     }
69
70     public @Nullable String getMacAddress() {
71         return getProp("mac-address");
72     }
73
74     public @Nullable String getSSID() {
75         return getProp("ssid");
76     }
77
78     public @Nullable String getInterfaceName() {
79         return getProp("interface");
80     }
81
82     public @Nullable BigInteger getTxBytes() {
83         return getBigIntProp("tx-byte");
84     }
85
86     public @Nullable BigInteger getRxBytes() {
87         return getBigIntProp("rx-byte");
88     }
89
90     public @Nullable BigInteger getTxPackets() {
91         return getBigIntProp("tx-packet");
92     }
93
94     public @Nullable BigInteger getRxPackets() {
95         return getBigIntProp("rx-packet");
96     }
97
98     public @Nullable String getUptime() {
99         return getProp("uptime");
100     }
101
102     public @Nullable LocalDateTime getUptimeStart() {
103         return Converter.routerosPeriodBack(getUptime());
104     }
105 }