import java.nio.charset.StandardCharsets;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.openhab.binding.tesla.internal.protocol.Event;
import org.openhab.core.io.net.http.WebSocketFactory;
+import org.openhab.core.thing.ThingUID;
+import org.openhab.core.thing.util.ThingWebClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private String endpointId;
protected WebSocketFactory webSocketFactory;
- private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger();
private WebSocketClient client;
private ConnectionState connectionState = ConnectionState.CLOSED;
private EventHandler eventHandler;
private final Gson gson = new Gson();
- public TeslaEventEndpoint(WebSocketFactory webSocketFactory) {
+ public TeslaEventEndpoint(ThingUID uid, WebSocketFactory webSocketFactory) {
try {
- this.endpointId = "TeslaEventEndpoint-" + INSTANCE_COUNTER.incrementAndGet();
+ this.endpointId = "TeslaEventEndpoint-" + uid.getAsString();
- client = webSocketFactory.createWebSocketClient(endpointId);
+ String name = ThingWebClientUtil.buildWebClientConsumerName(uid, null);
+ client = webSocketFactory.createWebSocketClient(name);
this.client.setConnectTimeout(TIMEOUT_MILLISECONDS);
this.client.setMaxIdleTimeout(IDLE_TIMEOUT_MILLISECONDS);
} catch (Exception e) {
if (enableEvents) {
if (eventThread == null) {
- eventThread = new Thread(eventRunnable, "openHAB-Tesla-Events-" + getThing().getUID());
+ eventThread = new Thread(eventRunnable, "OH-binding-" + getThing().getUID() + "-events");
eventThread.start();
}
}
@Override
public void run() {
- eventEndpoint = new TeslaEventEndpoint(webSocketFactory);
+ eventEndpoint = new TeslaEventEndpoint(getThing().getUID(), webSocketFactory);
eventEndpoint.addEventHandler(new TeslaEventEndpoint.EventHandler() {
@Override
public void handleEvent(Event event) {