]> git.basschouten.com Git - openhab-addons.git/blob
db7c7be5fc28d65bce68826dd9322542e3546298
[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.miele.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link FullyQualifiedApplianceIdentifier} class represents a fully qualified appliance identifier.
19  * Example: "hdm:ZigBee:0123456789abcdef#210"
20  *
21  * @author Jacob Laursen - Initial contribution
22  */
23 @NonNullByDefault
24 public class FullyQualifiedApplianceIdentifier {
25     private String uid;
26     private String protocol;
27     private String applianceId;
28
29     public FullyQualifiedApplianceIdentifier(String uid) {
30         this.uid = uid;
31
32         int separatorPosition = this.uid.lastIndexOf(':') + 1;
33         this.protocol = uid.substring(0, separatorPosition);
34         this.applianceId = uid.substring(separatorPosition);
35     }
36
37     public FullyQualifiedApplianceIdentifier(String applianceId, String protocol) {
38         this.uid = protocol + applianceId;
39         this.protocol = protocol;
40         this.applianceId = applianceId;
41     }
42
43     /**
44      * @return UID of appliance (e.g. "hdm:ZigBee:0123456789abcdef#210")
45      */
46     public String getUid() {
47         return this.uid;
48     }
49
50     /**
51      * @return Appliance ID without protocol adapter information (e.g. "0123456789abcdef#210")
52      */
53     public String getApplianceId() {
54         return this.applianceId;
55     }
56
57     public String getId() {
58         return this.getApplianceId().replaceAll("[^a-zA-Z0-9_]", "_");
59     }
60
61     /**
62      * @return Protocol prefix of fully qualified appliance identifier (e.g. "hdmi:ZigBee:")
63      */
64     public String getProtocol() {
65         return this.protocol;
66     }
67 }