2 * Copyright (c) 2010-2024 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.samsungtv.internal.config;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Configuration class for {@link org.openhab.binding.samsungtv.internal.handler.SamsungTvHandler}.
22 * @author Pauli Anttila - Initial contribution
23 * @author Arjan Mels - Added MAC Address
24 * @author Nick Waterton - added Smartthings, subscription, refactoring
28 public class SamsungTvConfiguration {
29 public static final String PROTOCOL = "protocol";
30 public static final String PROTOCOL_NONE = "None";
31 public static final String PROTOCOL_LEGACY = "Legacy";
32 public static final String PROTOCOL_WEBSOCKET = "WebSocket";
33 public static final String PROTOCOL_SECUREWEBSOCKET = "SecureWebSocket";
34 public static final String HOST_NAME = "hostName";
35 public static final String PORT = "port";
36 public static final String MAC_ADDRESS = "macAddress";
37 public static final String REFRESH_INTERVAL = "refreshInterval";
38 public static final String SUBSCRIPTION = "subscription";
39 public static final String WEBSOCKET_TOKEN = "webSocketToken";
40 public static final String SMARTTHINGS_API = "smartThingsApiKey";
41 public static final String SMARTTHINGS_DEVICEID = "smartThingsDeviceId";
42 public static final int PORT_DEFAULT_LEGACY = 55000;
43 public static final int PORT_DEFAULT_WEBSOCKET = 8001;
44 public static final int PORT_DEFAULT_SECUREWEBSOCKET = 8002;
46 public String protocol;
47 public String hostName;
48 public String macAddress;
50 public int refreshInterval;
51 public String webSocketToken;
52 public String smartThingsApiKey;
53 public String smartThingsDeviceId;
54 public boolean subscription;
56 public boolean isWebsocketProtocol() {
57 return PROTOCOL_WEBSOCKET.equals(getProtocol()) || PROTOCOL_SECUREWEBSOCKET.equals(getProtocol());
60 public String getProtocol() {
61 return Optional.ofNullable(protocol).orElse(PROTOCOL_NONE);
64 public String getHostName() {
65 return Optional.ofNullable(hostName).orElse("");
68 public String getMacAddress() {
69 return Optional.ofNullable(macAddress).filter(m -> m.length() == 17).orElse("");
72 public int getPort() {
73 return Optional.ofNullable(port).orElse(PORT_DEFAULT_LEGACY);
76 public int getRefreshInterval() {
77 return Optional.ofNullable(refreshInterval).orElse(1000);
80 public String getWebsocketToken() {
81 return Optional.ofNullable(webSocketToken).orElse("");
84 public String getSmartThingsApiKey() {
85 return Optional.ofNullable(smartThingsApiKey).orElse("");
88 public String getSmartThingsDeviceId() {
89 return Optional.ofNullable(smartThingsDeviceId).orElse("");
92 public boolean getSubscription() {
93 return Optional.ofNullable(subscription).orElse(false);