]> git.basschouten.com Git - openhab-addons.git/blob
73171a59fab78b7285c23ccebb32679bac61a8fa
[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.webthing.internal.client.dto;
14
15 import java.net.URI;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Optional;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * The Web Thing Description. Refer https://iot.mozilla.org/wot/#web-thing-description
24  *
25  * @author Gregor Roth - Initial contribution
26  */
27 public class WebThingDescription {
28
29     public String id = null;
30
31     public String title = "";
32
33     @SerializedName("@context")
34     public String contextKeyword = "";
35
36     public Map<String, Property> properties = Map.of();
37
38     public List<Link> links = List.of();
39
40     /**
41      * convenience method to read properties
42      * 
43      * @param propertyName the property name to read
44      * @return the property value
45      */
46     public Optional<Property> getProperty(String propertyName) {
47         return Optional.ofNullable(properties.get(propertyName));
48     }
49
50     /**
51      * convenience method to read the event stream uri
52      * 
53      * @return the optional event stream uri
54      */
55     public Optional<URI> getEventStreamUri() {
56         for (var link : this.links) {
57             var href = link.href;
58             if ((href != null) && href.startsWith("ws")) {
59                 var rel = Optional.ofNullable(link.rel).orElse("<undefined>");
60                 if ("alternate".equals(rel)) {
61                     return Optional.of(URI.create(href));
62                 }
63             }
64         }
65         return Optional.empty();
66     }
67 }