]> git.basschouten.com Git - openhab-addons.git/blob
87ee4d74e778869e9252fecf017a92346a7f6e13
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.samsungtv.internal.config;
14
15 import java.util.Optional;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Configuration class for {@link org.openhab.binding.samsungtv.internal.handler.SamsungTvHandler}.
21  *
22  * @author Pauli Anttila - Initial contribution
23  * @author Arjan Mels - Added MAC Address
24  * @author Nick Waterton - added Smartthings, subscription, refactoring
25  */
26
27 @NonNullByDefault({})
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;
45
46     public String protocol;
47     public String hostName;
48     public String macAddress;
49     public int port;
50     public int refreshInterval;
51     public String webSocketToken;
52     public String smartThingsApiKey;
53     public String smartThingsDeviceId;
54     public boolean subscription;
55
56     public boolean isWebsocketProtocol() {
57         return PROTOCOL_WEBSOCKET.equals(getProtocol()) || PROTOCOL_SECUREWEBSOCKET.equals(getProtocol());
58     }
59
60     public String getProtocol() {
61         return Optional.ofNullable(protocol).orElse(PROTOCOL_NONE);
62     }
63
64     public String getHostName() {
65         return Optional.ofNullable(hostName).orElse("");
66     }
67
68     public String getMacAddress() {
69         return Optional.ofNullable(macAddress).filter(m -> m.length() == 17).orElse("");
70     }
71
72     public int getPort() {
73         return Optional.ofNullable(port).orElse(PORT_DEFAULT_LEGACY);
74     }
75
76     public int getRefreshInterval() {
77         return Optional.ofNullable(refreshInterval).orElse(1000);
78     }
79
80     public String getWebsocketToken() {
81         return Optional.ofNullable(webSocketToken).orElse("");
82     }
83
84     public String getSmartThingsApiKey() {
85         return Optional.ofNullable(smartThingsApiKey).orElse("");
86     }
87
88     public String getSmartThingsDeviceId() {
89         return Optional.ofNullable(smartThingsDeviceId).orElse("");
90     }
91
92     public boolean getSubscription() {
93         return Optional.ofNullable(subscription).orElse(false);
94     }
95 }