]> git.basschouten.com Git - openhab-addons.git/blob
2a64ba5ba026a16a0a39dd8f64c7bcce7d63808d
[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.innogysmarthome.internal.client.entity.link;
14
15 import org.openhab.binding.innogysmarthome.internal.client.entity.capability.Capability;
16 import org.openhab.binding.innogysmarthome.internal.client.entity.device.Device;
17 import org.openhab.binding.innogysmarthome.internal.client.entity.message.Message;
18
19 /**
20  * Defines the data structure for a {@link Link}. This is the basic component used to link different data types in the
21  * innogy API.
22  *
23  * @author Oliver Kuhl - Initial contribution
24  */
25 public class Link {
26
27     public static final String LINK_TYPE_CAPABILITY = "/capability/";
28     public static final String LINK_TYPE_DEVICE = "/device/";
29     public static final String LINK_TYPE_MESSAGE = "/message/";
30     public static final String LINK_TYPE_SHC = "/desc/device/SHC.RWE/";
31     public static final String LINK_TYPE_UNKNOWN = "unknown";
32
33     /**
34      * Returns the Type of the {@link Link}.
35      *
36      * @return {@link #LINK_TYPE_CAPABILITY},{@link #LINK_TYPE_DEVICE}, {@link #LINK_TYPE_MESSAGE},
37      *         {@link #LINK_TYPE_SHC} or {@link #LINK_TYPE_UNKNOWN}
38      */
39     public static String getLinkType(String link) {
40         if (link.startsWith(LINK_TYPE_CAPABILITY)) {
41             return LINK_TYPE_CAPABILITY;
42         } else if (link.startsWith(LINK_TYPE_DEVICE)) {
43             return LINK_TYPE_DEVICE;
44         } else if (link.startsWith(LINK_TYPE_MESSAGE)) {
45             return LINK_TYPE_MESSAGE;
46         } else if (link.startsWith(LINK_TYPE_SHC)) {
47             return LINK_TYPE_SHC;
48         } else {
49             return LINK_TYPE_UNKNOWN;
50         }
51     }
52
53     /**
54      * Returns the id of the {@link Link} or null, if the link does not have an id or even no value.
55      *
56      * @return String the id of the link or null
57      */
58     public static String getId(String link) {
59         if (link != null) {
60             final String linkType = getLinkType(link);
61             if (linkType != null && !Link.LINK_TYPE_UNKNOWN.equals(linkType) && !Link.LINK_TYPE_SHC.equals(linkType)) {
62                 return link.replace(linkType, "");
63             }
64         }
65         return null;
66     }
67
68     /**
69      * Returns true, if the {@link Link} points to a {@link Capability}.
70      *
71      * @return
72      */
73     public static boolean isTypeCapability(String link) {
74         return LINK_TYPE_CAPABILITY.equals(Link.getLinkType(link));
75     }
76
77     /**
78      * Returns true, if the {@link Link} points to a {@link Device}.
79      *
80      * @return
81      */
82     public static boolean isTypeDevice(String link) {
83         return LINK_TYPE_DEVICE.equals(Link.getLinkType(link));
84     }
85
86     /**
87      * Returns true, if the {@link Link} points to a {@link Message}.
88      *
89      * @return
90      */
91     public static boolean isTypeMessage(String link) {
92         return LINK_TYPE_MESSAGE.equals(Link.getLinkType(link));
93     }
94
95     /**
96      * Returns true, if the {@link Link} points to a SHC.
97      *
98      * @return
99      */
100     public static boolean isTypeSHC(String link) {
101         return LINK_TYPE_SHC.equals(Link.getLinkType(link));
102     }
103
104     /**
105      * Returns true, if the {@link Link} points to something unknown.
106      *
107      * @return
108      */
109     public static boolean isTypeUnknown(String link) {
110         return LINK_TYPE_UNKNOWN.equals(Link.getLinkType(link));
111     }
112 }