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