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.tapocontrol.internal.structures;
15 import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
16 import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import com.google.gson.JsonObject;
23 * Tapo-Energy-Monitor Structure Class
25 * @author Christian Wild - Initial contribution
28 public class TapoEnergyData {
29 private Number currentPower = 0;
30 private Number todayEnergy = 0;
31 private Number monthEnergy = 0;
32 private Number todayRuntime = 0;
33 private Number monthRuntime = 0;
34 private Number[] past24h = new Number[24];
35 private Number[] past30d = new Number[30];
36 private Number[] past1y = new Number[12];
38 private JsonObject jsonObject = new JsonObject();
43 public TapoEnergyData() {
48 * Init DeviceInfo with new Data;
50 * @param jso JsonObject new Data
52 public TapoEnergyData(JsonObject jso) {
57 * Set Data (new JsonObject)
59 * @param jso JsonObject new Data
61 public TapoEnergyData setData(JsonObject jso) {
62 /* create empty jsonObject to set efault values if has no energydata */
63 if (jso.has(JSON_KEY_ENERGY_POWER)) {
64 this.jsonObject = jso;
66 this.jsonObject = new JsonObject();
72 private void setData() {
73 this.currentPower = (float) jsonObjectToInt(jsonObject, JSON_KEY_ENERGY_POWER) / 1000;
75 this.todayEnergy = jsonObjectToInt(jsonObject, JSON_KEY_ENERGY_ENERGY_TODAY);
76 this.monthEnergy = jsonObjectToInt(jsonObject, JSON_KEY_ENERGY_ENERGY_MONTH);
77 this.todayRuntime = jsonObjectToInt(jsonObject, JSON_KEY_ENERGY_RUNTIME_TODAY);
78 this.monthRuntime = jsonObjectToInt(jsonObject, JSON_KEY_ENERGY_RUNTIME_MONTH);
79 this.past24h = new Number[24];
80 this.past30d = new Number[30];
81 this.past1y = new Number[12];
84 /***********************************
88 ************************************/
90 public Number getCurrentPower() {
94 public Number getTodayEnergy() {
98 public Number getMonthEnergy() {
102 public Number getYearEnergy() {
104 for (int i = 0; i < past1y.length; i++) {
105 sum += past1y[i].intValue();
110 public Number getTodayRuntime() {
114 public Number getMonthRuntime() {
118 public Number[] getPast24hUsage() {
122 public Number[] getPast30dUsage() {
126 public Number[] getPast1yUsage() {