2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.webthing.internal.client.dto;
16 import java.util.List;
18 import java.util.Optional;
20 import com.google.gson.annotations.SerializedName;
23 * The Web Thing Description. Refer https://iot.mozilla.org/wot/#web-thing-description
25 * @author Gregor Roth - Initial contribution
27 public class WebThingDescription {
29 public String id = null;
31 public String title = "";
33 @SerializedName("@context")
34 public String contextKeyword = "";
36 public Map<String, Property> properties = Map.of();
38 public List<Link> links = List.of();
41 * convenience method to read properties
43 * @param propertyName the property name to read
44 * @return the property value
46 public Optional<Property> getProperty(String propertyName) {
47 return Optional.ofNullable(properties.get(propertyName));
51 * convenience method to read the event stream uri
53 * @return the optional event stream uri
55 public Optional<URI> getEventStreamUri() {
56 for (var link : this.links) {
58 if ((href != null) && href.startsWith("ws")) {
59 var rel = Optional.ofNullable(link.rel).orElse("<undefined>");
60 if (rel.equals("alternate")) {
61 return Optional.of(URI.create(href));
65 return Optional.empty();