]> git.basschouten.com Git - openhab-addons.git/blob
d0e0398b4d749780d28c114746d03d8ee612c4bc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.avmfritz.internal.dto;
14
15 import java.math.BigDecimal;
16
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlRootElement;
20 import javax.xml.bind.annotation.XmlType;
21
22 /**
23  * See {@link DeviceListModel}.
24  *
25  * @author Robert Bausdorf - Initial contribution
26  * @author Christoph Weitkamp - Added channel 'voltage'
27  */
28 @XmlAccessorType(XmlAccessType.FIELD)
29 @XmlType(propOrder = { "voltage", "power", "energy" })
30 @XmlRootElement(name = "powermeter")
31 public class PowerMeterModel {
32     public static final BigDecimal VOLTAGE_FACTOR = new BigDecimal("0.001");
33     public static final BigDecimal POWER_FACTOR = new BigDecimal("0.001");
34
35     private BigDecimal voltage;
36     private BigDecimal power;
37     private BigDecimal energy;
38
39     public BigDecimal getVoltage() {
40         return voltage != null ? VOLTAGE_FACTOR.multiply(voltage) : BigDecimal.ZERO;
41     }
42
43     public void setVoltage(BigDecimal voltage) {
44         this.voltage = voltage;
45     }
46
47     public BigDecimal getPower() {
48         return power != null ? POWER_FACTOR.multiply(power) : BigDecimal.ZERO;
49     }
50
51     public void setPower(BigDecimal power) {
52         this.power = power;
53     }
54
55     public BigDecimal getEnergy() {
56         return energy != null ? energy : BigDecimal.ZERO;
57     }
58
59     public void setEnergy(BigDecimal energy) {
60         this.energy = energy;
61     }
62
63     @Override
64     public String toString() {
65         return new StringBuilder().append("[voltage=").append(getVoltage()).append(",power=").append(getPower())
66                 .append(",energy=").append(getEnergy()).append("]").toString();
67     }
68 }