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.livisismarthome.internal.client;
15 import java.net.URLEncoder;
16 import java.nio.charset.StandardCharsets;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * The {@link URLCreator} is responsible for creating all required URLs.
23 * @author Sven Strohschein - Initial contribution
26 public final class URLCreator {
28 private URLCreator() {
31 public static String createTokenURL(String host) {
32 return createAddress(host) + "/auth/token";
35 public static String createDevicesURL(String host) {
36 return createAddress(host) + "/device";
39 public static String createDeviceStatesURL(String host) {
40 return createAddress(host) + "/device/states";
43 public static String createDeviceURL(String host, String deviceId) {
44 return createAddress(host) + "/device/" + deviceId;
47 public static String createDeviceStateURL(String host, String deviceId) {
48 return createAddress(host) + "/device/" + deviceId + "/state";
51 public static String createDeviceCapabilitiesURL(String host, String deviceId) {
52 return createAddress(host) + "/device/" + deviceId + "/capabilities";
55 public static String createCapabilityURL(String host) {
56 return createAddress(host) + "/capability";
59 public static String createCapabilityStatesURL(String host) {
60 return createAddress(host) + "/capability/states";
63 public static String createActionURL(String host) {
64 return createAddress(host) + "/action";
67 public static String createStatusURL(String host) {
68 return createAddress(host) + "/status";
71 public static String createLocationURL(String host) {
72 return createAddress(host) + "/location";
75 public static String createMessageURL(String host) {
76 return createAddress(host) + "/message";
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";
85 webSocketPort = "9090";
87 return "ws://" + host + ':' + webSocketPort + "/events?token=" + tokenURLEncoded;
90 private static String createAddress(String host) {
91 return "http://" + host + ":8080";