]> git.basschouten.com Git - openhab-addons.git/blob
1a4cefc51bedfae32e52c61f41a1cfd7c5ca21bc
[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.onewire.internal.owserver;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.onewire.internal.SensorId;
18
19 /**
20  * The {@link OwserverDeviceParameter} device parameter definition for owserver bridge handler
21  *
22  * @author Jan N. Klug - Initial contribution
23  */
24
25 @NonNullByDefault
26 public class OwserverDeviceParameter {
27     private String prefix = "";
28     private String path = "";
29
30     /**
31      * device parameter for owserver bridge handler
32      *
33      * @param prefix path prefix (e.g. "uncached/")
34      * @param path path without sensor id (e.g. "/humidity")
35      */
36     public OwserverDeviceParameter(String prefix, String path) {
37         if (prefix.endsWith("/")) {
38             this.prefix = prefix.substring(0, prefix.length() - 1);
39         } else {
40             this.prefix = prefix;
41         }
42         if (this.prefix.startsWith("/")) {
43             this.prefix = this.prefix.substring(1);
44         }
45         if (path.startsWith("/")) {
46             this.path = path;
47         } else {
48             this.path = "/" + path;
49         }
50     }
51
52     /**
53      * device parameter for owserver bridge handler
54      *
55      * @param path path without sensor id (e.g. "/humidity")
56      */
57     public OwserverDeviceParameter(String path) {
58         this("", path);
59     }
60
61     /**
62      * get the full owfs path for a given sensor id
63      *
64      * @param sensorId
65      */
66     public String getPath(SensorId sensorId) {
67         return prefix + sensorId.getFullPath() + path;
68     }
69
70     @Override
71     public String toString() {
72         return prefix + "/sensorId" + path;
73     }
74
75     @Override
76     public int hashCode() {
77         return toString().hashCode();
78     }
79
80     @Override
81     public boolean equals(@Nullable Object o) {
82         if (o == this) {
83             return true;
84         }
85
86         if (!(o instanceof OwserverDeviceParameter)) {
87             return false;
88         }
89
90         return ((OwserverDeviceParameter) o).toString().equals(toString());
91     }
92 }