]> git.basschouten.com Git - openhab-addons.git/blob
d583f73d2e1cf3b4489cc0db8f68fbbf45e945ef
[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 (path.startsWith("/")) {
43             this.path = path;
44         } else {
45             this.path = "/" + path;
46         }
47     }
48
49     /**
50      * device parameter for owserver bridge handler
51      *
52      * @param path path without sensor id (e.g. "/humidity")
53      */
54     public OwserverDeviceParameter(String path) {
55         this("", path);
56     }
57
58     /**
59      * get the full owfs path for a given sensor id
60      *
61      * @param sensorId
62      */
63     public String getPath(SensorId sensorId) {
64         return prefix + sensorId.getFullPath() + path;
65     }
66
67     @Override
68     public String toString() {
69         return prefix + "/sensorId" + path;
70     }
71
72     @Override
73     public int hashCode() {
74         return toString().hashCode();
75     }
76
77     @Override
78     public boolean equals(@Nullable Object o) {
79         if (o == this) {
80             return true;
81         }
82
83         if (!(o instanceof OwserverDeviceParameter)) {
84             return false;
85         }
86
87         return ((OwserverDeviceParameter) o).toString().equals(toString());
88     }
89 }