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.asuswrt.internal.structures;
15 import static org.openhab.binding.asuswrt.internal.helpers.AsuswrtUtils.jsonObjectToInt;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import com.google.gson.JsonObject;
22 * The {@link AsuswrtUsage} class handles usage statistics
24 * @author Christian Wild - Initial contribution
27 public class AsuswrtUsage {
28 private Integer free = 0;
29 private Integer used = 0;
30 private Integer total = 0;
32 public AsuswrtUsage() {
38 * @param jsonObject jsonObject data is stored
39 * @param totalKey name of key total available is stored
40 * @param usedKey name of key used is stored
42 public AsuswrtUsage(JsonObject jsonObject, String totalKey, String usedKey) {
43 setData(jsonObject, totalKey, usedKey);
49 * @param totalUsage the total usage
50 * @param used the usage
52 public AsuswrtUsage(Integer totalUsage, Integer used) {
53 setData(totalUsage, used);
61 * Sets the usage data from a JSON object.
63 * @param jsonObject the JSON object containing the data
64 * @param totalKey the key name with the 'total available' value
65 * @param usedKey the key name with the 'used' value
67 public void setData(JsonObject jsonObject, String totalKey, String usedKey) {
68 total = jsonObjectToInt(jsonObject, totalKey, 0);
69 used = jsonObjectToInt(jsonObject, usedKey, 0);
74 * Sets usage data from integer values.
76 * @param totalUsage the total available value
77 * @param used the used value
79 public void setData(Integer totalUsage, Integer used) {
89 public Integer getTotal() {
93 public Integer getUsed() {
97 public Integer getFree() {
101 public Integer getUsedPercent() {
103 return ((used * 100) / total);
108 public Integer getFreePercent() {
110 return ((free * 100) / total);