2 * Copyright (c) 2010-2022 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.tplinksmarthome.internal.model;
16 * Data class for reading tp-Link Smart Plug energy monitoring.
17 * Only getter methods as the values are set by gson based on the retrieved json.
19 * @author Hilbrand Bouwkamp - Initial contribution
21 public class Realtime extends ErrorResponse {
23 private static final int MILLIWATT_TO_WATT = 1000;
24 private static final int MILLIAMP_TO_AMP = 1000;
25 private static final int WATTHOUR_TO_KILOWATTHOUR = 1000;
26 private static final int MILLIVOLT_TO_VOLT = 1000;
28 private double current;
31 private double voltage;
33 // JSON names used for v2 hardware
34 private double currentMa;
35 private double powerMw;
36 private double totalWh;
37 private double voltageMv;
39 public double getCurrent() {
40 return currentMa > 0.0 ? currentMa / MILLIAMP_TO_AMP : current;
43 public double getPower() {
44 return powerMw > 0.0 ? powerMw / MILLIWATT_TO_WATT : power;
47 public double getTotal() {
48 return totalWh > 0.0 ? totalWh / WATTHOUR_TO_KILOWATTHOUR : total;
51 public double getVoltage() {
52 return voltageMv > 0.0 ? voltageMv / MILLIVOLT_TO_VOLT : voltage;
56 public String toString() {
57 return "current:" + getCurrent() + ", power:" + getPower() + ", total:" + getTotal() + ", voltage:"
58 + getVoltage() + super.toString();