]> git.basschouten.com Git - openhab-addons.git/blob
a53bc083f60afa9a7c4b15966a5dbf870ec2937d
[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.io.imperihome.internal.model.param;
14
15 import org.openhab.core.library.types.DecimalType;
16
17 /**
18  * Numeric value param
19  *
20  * @author Pepijn de Geus - Initial contribution
21  */
22 public class NumericValueParam extends DeviceParam {
23
24     private String unit;
25     private boolean graphable = true;
26
27     public NumericValueParam(ParamType type, String unit) {
28         super(type);
29         setUnit(unit);
30     }
31
32     public NumericValueParam(ParamType type, String unit, DecimalType value) {
33         this(type, unit);
34         setValue(value == null ? 0 : value.doubleValue());
35     }
36
37     @Override
38     public Number getValue() {
39         return (Number) super.getValue();
40     }
41
42     public void setValue(Number value) {
43         super.setValue(value);
44     }
45
46     public String getUnit() {
47         return unit;
48     }
49
50     public void setUnit(String unit) {
51         this.unit = unit;
52     }
53
54     public boolean isGraphable() {
55         return graphable;
56     }
57
58     public void setGraphable(boolean graphable) {
59         this.graphable = graphable;
60     }
61
62     @Override
63     public boolean equals(Object o) {
64         if (this == o) {
65             return true;
66         }
67         if (!(o instanceof NumericValueParam)) {
68             return false;
69         }
70         if (!super.equals(o)) {
71             return false;
72         }
73
74         NumericValueParam that = (NumericValueParam) o;
75
76         if (graphable != that.graphable) {
77             return false;
78         }
79         return unit != null ? unit.equals(that.unit) : that.unit == null;
80     }
81
82     @Override
83     public String toString() {
84         return "NumericValueParam{" + "super=" + super.toString() + ", unit='" + unit + '\'' + ", graphable="
85                 + graphable + '}';
86     }
87 }