]> git.basschouten.com Git - openhab-addons.git/blob
3e6a29af8e153a96a2f78b134c54c8921966da88
[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.binding.homeconnect.internal.client.model;
14
15 import static java.lang.Boolean.parseBoolean;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * Data model
22  *
23  * @author Jonas BrĂ¼stel - Initial contribution
24  *
25  */
26 @NonNullByDefault
27 public class Data {
28
29     private final String name;
30     private final @Nullable String value;
31     private final @Nullable String unit;
32
33     public Data(String name, @Nullable String value, @Nullable String unit) {
34         this.name = name;
35         this.value = value;
36         this.unit = unit;
37     }
38
39     public String getName() {
40         return name;
41     }
42
43     public @Nullable String getValue() {
44         return value;
45     }
46
47     public @Nullable String getUnit() {
48         return unit;
49     }
50
51     public int getValueAsInt() {
52         String stringValue = value;
53         return stringValue != null ? Float.valueOf(stringValue).intValue() : 0;
54     }
55
56     public boolean getValueAsBoolean() {
57         return parseBoolean(value);
58     }
59
60     @Override
61     public String toString() {
62         return "Data [name=" + name + ", value=" + value + ", unit=" + unit + "]";
63     }
64 }