Skip to content

Commit ab2bfc0

Browse files
committed
Removed redundant ip property.
Signed-off-by: Sebastian Prehn <[email protected]> (github: sprehn)
1 parent 608e530 commit ab2bfc0

File tree

5 files changed

+91
-14
lines changed

5 files changed

+91
-14
lines changed

addons/binding/org.openhab.binding.lgwebos/ESH-INF/thing/thing-types.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<channel id="appLauncher" typeId="appLauncherChannelType" />
2020

2121
</channels>
22-
23-
<!-- <config-description> <parameter name="ip" type="text" required="true"> <label>IP</label> <description>IP address of
24-
the WebOS TV.</description> <context>network-address</context> </parameter> </config-description> -->
25-
<properties>
26-
<property name="ip" />
27-
</properties>
2822
</thing-type>
2923

3024
<channel-type id="powerType">

addons/binding/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/LGWebOSBindingConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ public class LGWebOSBindingConstants {
4040
public static final String CHANNEL_MEDIA_STOP = "mediaStop";
4141
public static final String CHANNEL_APP_LAUNCHER = "appLauncher";
4242
public static final String CHANNEL_MEDIA_PLAYER = "mediaPlayer";
43-
public static final String PROPERTY_IP_ADDRESS = "ip";
4443
}

addons/binding/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/handler/LGWebOSHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ public void handleCommand(ChannelUID channelUID, Command command) {
8787
ConnectableDevice device = getDevice();
8888
if (device == null) {
8989
logger.debug("Device {} not found - most likely is is currently offline. Details: Channel {}, Command {}.",
90-
getThing().getProperties().get(PROPERTY_IP_ADDRESS), channelUID.getId(), command);
90+
getIpAddress(), channelUID.getId(), command);
9191
}
9292
handler.onReceiveCommand(device, channelUID.getId(), this, command);
9393
}
9494

9595
private ConnectableDevice getDevice() {
96-
String ip = getThing().getProperties().get(PROPERTY_IP_ADDRESS);
96+
String ip = getIpAddress();
9797
return discoveryManager.getCompatibleDevices().get(ip);
9898
}
9999

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

224224
@Override
225225
public void onDeviceUpdated(DiscoveryManager manager, ConnectableDevice device) {
226-
String ip = getThing().getProperties().get(PROPERTY_IP_ADDRESS);
226+
String ip = getIpAddress();
227227
if (device.getIpAddress().equals(ip)) {
228228
device.addListener(this);
229229
}
230230
}
231231

232+
private String getIpAddress() {
233+
return getThing().getUID().getId().replace("_", ".");
234+
}
235+
232236
@Override
233237
public void onDeviceRemoved(DiscoveryManager manager, ConnectableDevice device) {
234238
// NOP

addons/binding/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/discovery/LGWebOSDiscovery.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
package org.openhab.binding.lgwebos.internal.discovery;
1010

11-
import static org.openhab.binding.lgwebos.LGWebOSBindingConstants.*;
11+
import static org.openhab.binding.lgwebos.LGWebOSBindingConstants.THING_TYPE_WEBOSTV;
1212

1313
import java.io.File;
1414
import java.net.InetAddress;
@@ -130,8 +130,7 @@ public void onDiscoveryFailed(DiscoveryManager manager, ServiceCommandError erro
130130
// Helpers for DiscoveryManagerListener Impl
131131
private DiscoveryResult createDiscoveryResult(ConnectableDevice device) {
132132
ThingUID thingUID = createThingUID(device);
133-
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID)
134-
.withProperty(PROPERTY_IP_ADDRESS, device.getIpAddress()).withLabel(device.getFriendlyName()).build();
133+
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(device.getFriendlyName()).build();
135134
return result;
136135
}
137136

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.openhab.binding.lgwebos.internal.discovery;
2+
3+
import java.util.Collections;
4+
import java.util.Set;
5+
6+
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
7+
import org.eclipse.smarthome.config.discovery.UpnpDiscoveryParticipant;
8+
import org.eclipse.smarthome.core.thing.ThingTypeUID;
9+
import org.eclipse.smarthome.core.thing.ThingUID;
10+
import org.jupnp.UpnpService;
11+
import org.jupnp.model.meta.RemoteDevice;
12+
import org.jupnp.model.meta.RemoteService;
13+
import org.openhab.binding.lgwebos.LGWebOSBindingConstants;
14+
import org.osgi.service.component.annotations.Component;
15+
import org.osgi.service.component.annotations.Reference;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
@Component(immediate = true)
20+
public class LGWebOSUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
21+
private final Logger logger = LoggerFactory.getLogger(LGWebOSUpnpDiscoveryParticipant.class);
22+
private final String URN = "urn:lge-com:service:webos-second-screen:1";
23+
private UpnpService upnpService;
24+
25+
@Reference
26+
protected void setUpnpService(UpnpService upnpService) {
27+
this.upnpService = upnpService;
28+
}
29+
30+
protected void unsetUpnpService(UpnpService upnpService) {
31+
this.upnpService = null;
32+
}
33+
34+
@Override
35+
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
36+
return Collections.singleton(LGWebOSBindingConstants.THING_TYPE_WEBOSTV);
37+
}
38+
39+
@Override
40+
public DiscoveryResult createResult(RemoteDevice device) {
41+
42+
String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
43+
if ("LG Electronics".equals(manufacturer)) {
44+
String modelName = device.getDetails().getModelDetails().getModelName();
45+
String friedlyName = device.getDetails().getFriendlyName();
46+
for (RemoteService s : device.getServices()) {
47+
logger.info("{}", s);
48+
}
49+
}
50+
51+
return null;
52+
}
53+
54+
@Override
55+
public ThingUID getThingUID(RemoteDevice device) {
56+
if (device != null) {
57+
58+
String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
59+
String modelName = device.getDetails().getModelDetails().getModelName();
60+
String friedlyName = device.getDetails().getFriendlyName();
61+
62+
if (manufacturer != null && modelName != null) {
63+
64+
// UDN shouldn't contain '-' characters.
65+
String udn = device.getIdentity().getUdn().getIdentifierString().replace("-", "_");
66+
67+
// One Samsung TV contains several UPnP devices.
68+
69+
// if (device.getType().getType().equals("MediaRenderer")) {
70+
71+
logger.debug("Discovered a LG TV '{}' model '{}' thing with UDN '{}'", friedlyName, modelName, udn);
72+
73+
// return new ThingUID(LGWebOSBindingConstants.THING_TYPE_WEBOSTV, udn);
74+
75+
// }
76+
}
77+
}
78+
return null;
79+
}
80+
81+
}

0 commit comments

Comments
 (0)