]> git.basschouten.com Git - openhab-addons.git/blob
5ff392c92ef093e00aff540d65556e206689a9c5
[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 String SMARTTHINGS_SUBSCRIPTION = "smartThingsSubscription";
43     public static final String ORIENTATION_KEY = "orientationKey";
44     public static final int PORT_DEFAULT_LEGACY = 55000;
45     public static final int PORT_DEFAULT_WEBSOCKET = 8001;
46     public static final int PORT_DEFAULT_SECUREWEBSOCKET = 8002;
47
48     public String protocol;
49     public String hostName;
50     public String macAddress;
51     public int port;
52     public int refreshInterval;
53     public String webSocketToken;
54     public String smartThingsApiKey;
55     public String smartThingsDeviceId;
56     public boolean subscription;
57     public boolean smartThingsSubscription;
58     public String orientationKey;
59
60     public boolean isWebsocketProtocol() {
61         return PROTOCOL_WEBSOCKET.equals(getProtocol()) || PROTOCOL_SECUREWEBSOCKET.equals(getProtocol());
62     }
63
64     public String getProtocol() {
65         return Optional.ofNullable(protocol).orElse(PROTOCOL_NONE);
66     }
67
68     public String getHostName() {
69         return Optional.ofNullable(hostName).orElse("");
70     }
71
72     public String getMacAddress() {
73         return Optional.ofNullable(macAddress).filter(m -> m.length() == 17).orElse("");
74     }
75
76     public int getPort() {
77         return Optional.ofNullable(port).orElse(PORT_DEFAULT_LEGACY);
78     }
79
80     public int getRefreshInterval() {
81         return Optional.ofNullable(refreshInterval).orElse(1000);
82     }
83
84     public String getWebsocketToken() {
85         return Optional.ofNullable(webSocketToken).orElse("");
86     }
87
88     public String getSmartThingsApiKey() {
89         return Optional.ofNullable(smartThingsApiKey).orElse("");
90     }
91
92     public String getSmartThingsDeviceId() {
93         return Optional.ofNullable(smartThingsDeviceId).orElse("");
94     }
95
96     public boolean getSubscription() {
97         return Optional.ofNullable(subscription).orElse(false);
98     }
99
100     public boolean getSmartThingsSubscription() {
101         return Optional.ofNullable(smartThingsSubscription).orElse(false);
102     }
103
104     public String getOrientationKey() {
105         return Optional.ofNullable(orientationKey).orElse("");
106     }
107 }