]> git.basschouten.com Git - openhab-addons.git/blob
970693b0624ceb907f935a19fef2eae2657f3f47
[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.livisismarthome.internal.client;
14
15 import java.net.URLEncoder;
16 import java.nio.charset.StandardCharsets;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * The {@link URLCreator} is responsible for creating all required URLs.
22  *
23  * @author Sven Strohschein - Initial contribution
24  */
25 @NonNullByDefault
26 public final class URLCreator {
27
28     private URLCreator() {
29     }
30
31     public static String createTokenURL(String host) {
32         return createAddress(host) + "/auth/token";
33     }
34
35     public static String createDevicesURL(String host) {
36         return createAddress(host) + "/device";
37     }
38
39     public static String createDeviceStatesURL(String host) {
40         return createAddress(host) + "/device/states";
41     }
42
43     public static String createDeviceURL(String host, String deviceId) {
44         return createAddress(host) + "/device/" + deviceId;
45     }
46
47     public static String createDeviceStateURL(String host, String deviceId) {
48         return createAddress(host) + "/device/" + deviceId + "/state";
49     }
50
51     public static String createDeviceCapabilitiesURL(String host, String deviceId) {
52         return createAddress(host) + "/device/" + deviceId + "/capabilities";
53     }
54
55     public static String createCapabilityURL(String host) {
56         return createAddress(host) + "/capability";
57     }
58
59     public static String createCapabilityStatesURL(String host) {
60         return createAddress(host) + "/capability/states";
61     }
62
63     public static String createActionURL(String host) {
64         return createAddress(host) + "/action";
65     }
66
67     public static String createStatusURL(String host) {
68         return createAddress(host) + "/status";
69     }
70
71     public static String createLocationURL(String host) {
72         return createAddress(host) + "/location";
73     }
74
75     public static String createMessageURL(String host) {
76         return createAddress(host) + "/message";
77     }
78
79     public static String createEventsURL(String host, String token, boolean isClassicController) {
80         final String tokenURLEncoded = URLEncoder.encode(token, StandardCharsets.UTF_8);
81         final String webSocketPort;
82         if (isClassicController) {
83             webSocketPort = "8080";
84         } else {
85             webSocketPort = "9090";
86         }
87         return "ws://" + host + ':' + webSocketPort + "/events?token=" + tokenURLEncoded;
88     }
89
90     private static String createAddress(String host) {
91         return "http://" + host + ":8080";
92     }
93 }