Skip to content

Commit

Permalink
Removed redundant ip property.
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Prehn <[email protected]> (github: sprehn)
  • Loading branch information
sprehn committed Nov 6, 2017
1 parent 608e530 commit ab2bfc0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
<channel id="appLauncher" typeId="appLauncherChannelType" />

</channels>

<!-- <config-description> <parameter name="ip" type="text" required="true"> <label>IP</label> <description>IP address of
the WebOS TV.</description> <context>network-address</context> </parameter> </config-description> -->
<properties>
<property name="ip" />
</properties>
</thing-type>

<channel-type id="powerType">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ public class LGWebOSBindingConstants {
public static final String CHANNEL_MEDIA_STOP = "mediaStop";
public static final String CHANNEL_APP_LAUNCHER = "appLauncher";
public static final String CHANNEL_MEDIA_PLAYER = "mediaPlayer";
public static final String PROPERTY_IP_ADDRESS = "ip";
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public void handleCommand(ChannelUID channelUID, Command command) {
ConnectableDevice device = getDevice();
if (device == null) {
logger.debug("Device {} not found - most likely is is currently offline. Details: Channel {}, Command {}.",
getThing().getProperties().get(PROPERTY_IP_ADDRESS), channelUID.getId(), command);
getIpAddress(), channelUID.getId(), command);
}
handler.onReceiveCommand(device, channelUID.getId(), this, command);
}

private ConnectableDevice getDevice() {
String ip = getThing().getProperties().get(PROPERTY_IP_ADDRESS);
String ip = getIpAddress();
return discoveryManager.getCompatibleDevices().get(ip);
}

Expand Down Expand Up @@ -213,7 +213,7 @@ private void refreshAllChannelSubscriptions(ConnectableDevice device) {
// just to make sure, this device is registered, if it was powered off during initialization
@Override
public void onDeviceAdded(DiscoveryManager manager, ConnectableDevice device) {
String ip = getThing().getProperties().get(PROPERTY_IP_ADDRESS);
String ip = getIpAddress();
if (device.getIpAddress().equals(ip)) {
device.addListener(this);
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, "Device Ready");
Expand All @@ -223,12 +223,16 @@ public void onDeviceAdded(DiscoveryManager manager, ConnectableDevice device) {

@Override
public void onDeviceUpdated(DiscoveryManager manager, ConnectableDevice device) {
String ip = getThing().getProperties().get(PROPERTY_IP_ADDRESS);
String ip = getIpAddress();
if (device.getIpAddress().equals(ip)) {
device.addListener(this);
}
}

private String getIpAddress() {
return getThing().getUID().getId().replace("_", ".");
}

@Override
public void onDeviceRemoved(DiscoveryManager manager, ConnectableDevice device) {
// NOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
package org.openhab.binding.lgwebos.internal.discovery;

import static org.openhab.binding.lgwebos.LGWebOSBindingConstants.*;
import static org.openhab.binding.lgwebos.LGWebOSBindingConstants.THING_TYPE_WEBOSTV;

import java.io.File;
import java.net.InetAddress;
Expand Down Expand Up @@ -130,8 +130,7 @@ public void onDiscoveryFailed(DiscoveryManager manager, ServiceCommandError erro
// Helpers for DiscoveryManagerListener Impl
private DiscoveryResult createDiscoveryResult(ConnectableDevice device) {
ThingUID thingUID = createThingUID(device);
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID)
.withProperty(PROPERTY_IP_ADDRESS, device.getIpAddress()).withLabel(device.getFriendlyName()).build();
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(device.getFriendlyName()).build();
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.openhab.binding.lgwebos.internal.discovery;

import java.util.Collections;
import java.util.Set;

import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.UpnpDiscoveryParticipant;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.jupnp.UpnpService;
import org.jupnp.model.meta.RemoteDevice;
import org.jupnp.model.meta.RemoteService;
import org.openhab.binding.lgwebos.LGWebOSBindingConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate = true)
public class LGWebOSUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
private final Logger logger = LoggerFactory.getLogger(LGWebOSUpnpDiscoveryParticipant.class);
private final String URN = "urn:lge-com:service:webos-second-screen:1";
private UpnpService upnpService;

@Reference
protected void setUpnpService(UpnpService upnpService) {
this.upnpService = upnpService;
}

protected void unsetUpnpService(UpnpService upnpService) {
this.upnpService = null;
}

@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(LGWebOSBindingConstants.THING_TYPE_WEBOSTV);
}

@Override
public DiscoveryResult createResult(RemoteDevice device) {

String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
if ("LG Electronics".equals(manufacturer)) {
String modelName = device.getDetails().getModelDetails().getModelName();
String friedlyName = device.getDetails().getFriendlyName();
for (RemoteService s : device.getServices()) {
logger.info("{}", s);
}
}

return null;
}

@Override
public ThingUID getThingUID(RemoteDevice device) {
if (device != null) {

String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
String modelName = device.getDetails().getModelDetails().getModelName();
String friedlyName = device.getDetails().getFriendlyName();

if (manufacturer != null && modelName != null) {

// UDN shouldn't contain '-' characters.
String udn = device.getIdentity().getUdn().getIdentifierString().replace("-", "_");

// One Samsung TV contains several UPnP devices.

// if (device.getType().getType().equals("MediaRenderer")) {

logger.debug("Discovered a LG TV '{}' model '{}' thing with UDN '{}'", friedlyName, modelName, udn);

// return new ThingUID(LGWebOSBindingConstants.THING_TYPE_WEBOSTV, udn);

// }
}
}
return null;
}

}

0 comments on commit ab2bfc0

Please sign in to comment.