]> git.basschouten.com Git - openhab-addons.git/blob
a5bbc36e6b3fed6fd4c02c6430b8835f3ac1381b
[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 java.time.LocalDateTime;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.mikrotik.internal.util.Converter;
21
22 /**
23  * The {@link RouterosSystemResources} is a model class for RouterOS system info having casting accessors for
24  * data that is available through bridge thing channels.
25  *
26  * @author Oleg Vivtash - Initial contribution
27  */
28 @NonNullByDefault
29 public class RouterosSystemResources extends RouterosBaseData {
30
31     public RouterosSystemResources(Map<String, String> props) {
32         super(props);
33     }
34
35     public @Nullable Integer getFreeSpace() {
36         return getIntProp("free-hdd-space");
37     }
38
39     public @Nullable Integer getTotalSpace() {
40         return getIntProp("total-hdd-space");
41     }
42
43     public @Nullable Integer getSpaceUse() {
44         Integer freeSpace = getFreeSpace(), totalSpace = getTotalSpace();
45         if (freeSpace == null || totalSpace == null) {
46             return null;
47         }
48         return 100 - Math.round(100F * freeSpace / totalSpace);
49     }
50
51     public @Nullable Integer getFreeMem() {
52         return getIntProp("free-memory");
53     }
54
55     public @Nullable Integer getTotalMem() {
56         return getIntProp("total-memory");
57     }
58
59     public @Nullable Integer getMemUse() {
60         Integer freeMem = getFreeMem(), totalMem = getTotalMem();
61         if (freeMem == null || totalMem == null) {
62             return null;
63         }
64         return 100 - Math.round(100F * freeMem / totalMem);
65     }
66
67     public @Nullable Integer getCpuLoad() {
68         return getIntProp("cpu-load");
69     }
70
71     public @Nullable String getUptime() {
72         return getProp("uptime");
73     }
74
75     public @Nullable LocalDateTime getUptimeStart() {
76         return Converter.routerosPeriodBack(getUptime());
77     }
78 }