Skip to content

Commit

Permalink
[lgwebos] Removal of connectsdk library and its dependencies. (#6060)
Browse files Browse the repository at this point in the history
* Removal of connectsdk library and its dependencies.
* Replaced connectsdk with OH native json, websocket, UpnpDiscovery.

Signed-off-by: Sebastian Prehn <[email protected]>
  • Loading branch information
sprehn authored and J-N-K committed Sep 26, 2019
1 parent 819de90 commit eef13d5
Show file tree
Hide file tree
Showing 42 changed files with 2,890 additions and 983 deletions.
1 change: 0 additions & 1 deletion bundles/org.openhab.binding.lgwebos/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/Connect-SDK-Java-Core-1.0.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
22 changes: 3 additions & 19 deletions bundles/org.openhab.binding.lgwebos/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ https://github.com/openhab/openhab2-addons

== Third-party Content

Connect-SDK-Java-Core
* License: Apache 2.0 License
* Project: https://github.com/ConnectSDK/Connect-SDK-Android-Core
* Source: https://github.com/sprehn/Connect-SDK-Java-Core/releases

Java-WebSocket
* License: MIT License
* Project: https://tootallnate.github.io/Java-WebSocket
* Source: https://github.com/TooTallNate/Java-WebSocket

json
* License: JSON License
* Project: https://www.json.org
* Source: https://github.com/douglascrockford/JSON-java

xpp3
* License: Apache 2.0 License
* Project: http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1
* Source: http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1
The web socket communication with LGWebOS is derived from Connect-SDK-Java-Core.
* License: Apache 2.0 License
* Project: https://github.com/ConnectSDK/Connect-SDK-Android-Core
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.lgwebos/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LG webOS Binding

The binding integrates LG WebOS based smart TVs.
This binding uses a [forked version](https://github.com/sprehn/Connect-SDK-Java-Core) of LG's [Connect SDK](https://github.com/ConnectSDK/Connect-SDK-Android-Core) library.
This binding is an adoption of LG's [Connect SDK](https://github.com/ConnectSDK/Connect-SDK-Android-Core) library, which is no longer maintained and which was specific to Android.

## Supported Things

Expand Down
Binary file not shown.
21 changes: 0 additions & 21 deletions bundles/org.openhab.binding.lgwebos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,4 @@

<name>openHAB Add-ons :: Bundles :: LG webOS Binding</name>

<dependencies>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.4c</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openhab.osgiify</groupId>
<artifactId>org.java-websocket.java-websocket</artifactId>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

<feature name="openhab-binding-lgwebos" description="LG webOS Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.apache.httpcomponents/httpcore-osgi/4.4.4</bundle>
<bundle dependency="true">mvn:org.apache.httpcomponents/httpclient-osgi/4.5.2</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xpp3/1.1.4c_7</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.json/20140107_1</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/org.java-websocket.java-websocket/1.3.2</bundle>
<feature>openhab-transport-upnp</feature>
<feature>openhab.tp-httpclient</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.lgwebos/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.lgwebos.action;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* This represents id and name of a WebOS application.
*
* @author Sebastian Prehn - Initial contribution
*/
@NonNullByDefault
public class Application {
private String id;
private String name;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,62 @@
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.openhab.binding.lgwebos.internal.handler.LGWebOSHandler;
import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription;
import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.connectsdk.device.ConnectableDevice;
import com.connectsdk.service.capability.listeners.ResponseListener;
import com.connectsdk.service.command.ServiceCommandError;
import com.connectsdk.service.command.ServiceSubscription;

/**
* An abstract implementation of ChannelHander which serves as a base class for all concrete instances.
*
* @author Sebastian Prehn - initial contribution
*/
@NonNullByDefault
abstract class BaseChannelHandler<T, R> implements ChannelHandler {
abstract class BaseChannelHandler<T> implements ChannelHandler {
private final Logger logger = LoggerFactory.getLogger(BaseChannelHandler.class);

private final ResponseListener<R> defaultResponseListener = new ResponseListener<R>() {
private final ResponseListener<T> defaultResponseListener = createResponseListener();

@Override
public void onError(@Nullable ServiceCommandError error) {
logger.warn("{}: received error response: ", getClass().getName(), error);
}
protected <Y> ResponseListener<Y> createResponseListener() {
return new ResponseListener<Y>() {

@Override
public void onSuccess(R object) {
logger.debug("{}: {}.", getClass().getName(), object);
}
};
@Override
public void onError(String error) {
logger.warn("{} received error response: {}", BaseChannelHandler.this.getClass().getSimpleName(),
error);
}

@Override
public void onSuccess(Y object) {
logger.debug("{} received: {}.", BaseChannelHandler.this.getClass().getSimpleName(), object);
}
};
}

// IP to Subscriptions map
private Map<String, ServiceSubscription<T>> subscriptions = new ConcurrentHashMap<>();
private Map<ThingUID, ServiceSubscription<T>> subscriptions = new ConcurrentHashMap<>();

@Override
public void onDeviceReady(ConnectableDevice device, String channelId, LGWebOSHandler handler) {
public void onDeviceReady(String channelId, LGWebOSHandler handler) {
// NOP
}

@Override
public void onDeviceRemoved(ConnectableDevice device, String channelId, LGWebOSHandler handler) {
public void onDeviceRemoved(String channelId, LGWebOSHandler handler) {
// NOP
}

@Override
public final synchronized void refreshSubscription(ConnectableDevice device, String channelId,
LGWebOSHandler handler) {
removeAnySubscription(device);
public final synchronized void refreshSubscription(String channelId, LGWebOSHandler handler) {
removeAnySubscription(handler);
if (handler.isChannelInUse(channelId)) { // only listen if least one item is configured for this channel
Optional<ServiceSubscription<T>> listener = getSubscription(device, channelId, handler);
Optional<ServiceSubscription<T>> listener = getSubscription(channelId, handler);

if (listener.isPresent()) {
logger.debug("Subscribed {} on IP: {}", this.getClass().getName(), device.getIpAddress());
subscriptions.put(device.getIpAddress(), listener.get());
logger.debug("Subscribed {} on IP: {}", this.getClass().getName(), handler.getThing().getUID());
subscriptions.put(handler.getThing().getUID(), listener.get());
}
}
}
Expand All @@ -85,37 +86,21 @@ public final synchronized void refreshSubscription(ConnectableDevice device, Str
* @return an {@code Optional} containing the ServiceSubscription, or an empty {@code Optional} if subscription is
* not supported.
*/
protected Optional<ServiceSubscription<T>> getSubscription(ConnectableDevice device, String channelId,
LGWebOSHandler handler) {
protected Optional<ServiceSubscription<T>> getSubscription(String channelId, LGWebOSHandler handler) {
return Optional.empty();
}

@Override
public final synchronized void removeAnySubscription(ConnectableDevice device) {
ServiceSubscription<T> l = subscriptions.remove(device.getIpAddress());
public final synchronized void removeAnySubscription(LGWebOSHandler handler) {
ServiceSubscription<T> l = subscriptions.remove(handler.getThing().getUID());
if (l != null) {
l.unsubscribe();
logger.debug("Unsubscribed {} on IP: {}", this.getClass().getName(), device.getIpAddress());
handler.getSocket().unsubscribe(l);
logger.debug("Unsubscribed {} on IP: {}", this.getClass().getName(), handler.getThing().getUID());
}
}

protected ResponseListener<R> getDefaultResponseListener() {
protected ResponseListener<T> getDefaultResponseListener() {
return defaultResponseListener;
}

/**
* A convenience method that calls device.hasCapability, but logs a message if the result is false.
*
* @param device the webos tv
* @param capability the capability to check
*
*/
protected boolean hasCapability(ConnectableDevice device, String capability) {
boolean result = device.hasCapability(capability);
if (!result) {
logger.debug("Device {} does not have capability {} as required by handler {}", device.getFriendlyName(),
capability, this.getClass().getName());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
package org.openhab.binding.lgwebos.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.lgwebos.internal.handler.LGWebOSHandler;

import com.connectsdk.device.ConnectableDevice;

/**
* Channel Handler mediates between connect sdk device state changes and openhab channel events.
*
Expand All @@ -31,13 +28,11 @@ public interface ChannelHandler {
* This method will be called whenever a command is received for this handler.
* All implementations provide custom logic here.
*
* @param device may be <code>null</code> in case the device is currently offline
* @param channelId must not be <code>null</code>
* @param handler must not be <code>null</code>
* @param command must not be <code>null</code>
*/
void onReceiveCommand(@Nullable ConnectableDevice device, String channelId, LGWebOSHandler handler,
Command command);
void onReceiveCommand(String channelId, LGWebOSHandler handler, Command command);

/**
* Handle underlying subscription status if device changes online state, capabilities or channel gets linked or
Expand All @@ -47,35 +42,32 @@ void onReceiveCommand(@Nullable ConnectableDevice device, String channelId, LGWe
* subscription on this device channel
* and handler.
*
* @param device must not be <code>null</code>
* @param channelId must not be <code>null</code>
* @param handler must not be <code>null</code>
*/
void refreshSubscription(ConnectableDevice device, String channelId, LGWebOSHandler handler);
void refreshSubscription(String channelId, LGWebOSHandler handler);

/**
* Removes subscriptions if there are any.
*
* @param device must not be <code>null</code>
* @param handler must not be <code>null</code>
*/
void removeAnySubscription(ConnectableDevice device);
void removeAnySubscription(LGWebOSHandler handler);

/**
* Callback method whenever a device disappears.
*
* @param device must not be <code>null</code>
* @param channelId must not be <code>null</code>
* @param handler must not be <code>null</code>
*/
void onDeviceRemoved(ConnectableDevice device, String channelId, LGWebOSHandler handler);
void onDeviceRemoved(String channelId, LGWebOSHandler handler);

/**
* Callback method whenever a device is discovered and ready to operate.
*
* @param device must not be <code>null</code>
* @param channelId must not be <code>null</code>
* @param handler must not be <code>null</code>
*/
void onDeviceReady(ConnectableDevice device, String channelId, LGWebOSHandler handler);
void onDeviceReady(String channelId, LGWebOSHandler handler);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import java.util.Collections;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.jupnp.model.types.ServiceType;

/**
* This class defines common constants, which are used across the whole binding.
*
* @author Sebastian Prehn - initial contribution
* @author Sebastian Prehn - Initial contribution
*/
@NonNullByDefault
public class LGWebOSBindingConstants {
Expand All @@ -30,13 +32,36 @@ public class LGWebOSBindingConstants {

public static final ThingTypeUID THING_TYPE_WEBOSTV = new ThingTypeUID(BINDING_ID, "WebOSTV");

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_WEBOSTV);
public static final Set<@NonNull ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(THING_TYPE_WEBOSTV);

public static final String BINDING_CONFIGURATION_LOCALIP = "localIP";
public static final ServiceType UPNP_SERVICE_TYPE = new ServiceType("lge-com", "webos-second-screen", 1);

/*
* Config names must match property names in
* - WebOSConfiguration
* - parameter names in ESH-INF/config/config.xml
* - property names in ESH-INF/thing/thing-types.xml
*/
public static final String CONFIG_HOST = "host";
public static final String CONFIG_KEY = "key";

/*
* Property names must match property names in
* - property names in ESH-INF/thing/thing-types.xml
*/
public static final String PROPERTY_DEVICE_ID = "deviceId";
public static final String PROPERTY_DEVICE_OS = "deviceOS";
public static final String PROPERTY_DEVICE_OS_VERSION = "deviceOSVersion";
public static final String PROPERTY_DEVICE_OS_RELEASE_VERSION = "deviceOSReleaseVersion";
public static final String PROPERTY_LAST_CONNECTED = "lastConnected";
public static final String PROPERTY_MODEL_NAME = "modelName";
public static final String PROPERTY_MANUFACTURER = "manufacturer";

// List of all Channel ids. Values have to match ids in thing-types.xml
/*
* List of all Channel ids.
* Values have to match ids in thing-types.xml
*/
public static final String CHANNEL_VOLUME = "volume";
public static final String CHANNEL_POWER = "power";
public static final String CHANNEL_MUTE = "mute";
Expand Down
Loading

0 comments on commit eef13d5

Please sign in to comment.