Skip to content

Commit 54bb7a7

Browse files
wbornmarkus7017
authored andcommitted
Fix missing bridge UID in thing UID during discovery (openhab#8449)
Fixes exceptions thrown in OH3 when building discovery results for things with bridges where the thing UID is missing the bridge UID. Related to openhab/openhab-core#1481 Signed-off-by: Wouter Born <[email protected]>
1 parent 3a39ab8 commit 54bb7a7

File tree

11 files changed

+34
-40
lines changed

11 files changed

+34
-40
lines changed

bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/AmazonEchoDiscovery.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@
1212
*/
1313
package org.openhab.binding.amazonechocontrol.internal.discovery;
1414

15-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.DEVICE_PROPERTY_FAMILY;
16-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.DEVICE_PROPERTY_FLASH_BRIEFING_PROFILE;
17-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.DEVICE_PROPERTY_SERIAL_NUMBER;
18-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.SUPPORTED_ECHO_THING_TYPES_UIDS;
19-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.THING_TYPE_ECHO;
20-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.THING_TYPE_ECHO_SHOW;
21-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.THING_TYPE_ECHO_SPOT;
22-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.THING_TYPE_ECHO_WHA;
23-
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.THING_TYPE_FLASH_BRIEFING_PROFILE;
15+
import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.*;
2416

2517
import java.util.Date;
2618
import java.util.HashMap;
@@ -160,13 +152,13 @@ synchronized void setDevices(List<Device> deviceList) {
160152
continue;
161153
}
162154

163-
ThingUID brigdeThingUID = this.accountHandler.getThing().getUID();
164-
ThingUID thingUID = new ThingUID(thingTypeId, brigdeThingUID, serialNumber);
155+
ThingUID bridgeThingUID = this.accountHandler.getThing().getUID();
156+
ThingUID thingUID = new ThingUID(thingTypeId, bridgeThingUID, serialNumber);
165157

166158
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(device.accountName)
167159
.withProperty(DEVICE_PROPERTY_SERIAL_NUMBER, serialNumber)
168160
.withProperty(DEVICE_PROPERTY_FAMILY, deviceFamily)
169-
.withRepresentationProperty(DEVICE_PROPERTY_SERIAL_NUMBER).withBridge(brigdeThingUID)
161+
.withRepresentationProperty(DEVICE_PROPERTY_SERIAL_NUMBER).withBridge(bridgeThingUID)
170162
.build();
171163

172164
logger.debug("Device [{}: {}] found. Mapped to thing type {}", device.deviceFamily, serialNumber,
@@ -184,8 +176,8 @@ public synchronized void discoverFlashBriefingProfiles(String currentFlashBriefi
184176
}
185177

186178
if (!discoveredFlashBriefings.contains(currentFlashBriefingJson)) {
187-
ThingUID brigdeThingUID = this.accountHandler.getThing().getUID();
188-
ThingUID freeThingUID = new ThingUID(THING_TYPE_FLASH_BRIEFING_PROFILE, brigdeThingUID,
179+
ThingUID bridgeThingUID = this.accountHandler.getThing().getUID();
180+
ThingUID freeThingUID = new ThingUID(THING_TYPE_FLASH_BRIEFING_PROFILE, bridgeThingUID,
189181
Integer.toString(currentFlashBriefingJson.hashCode()));
190182
DiscoveryResult result = DiscoveryResultBuilder.create(freeThingUID).withLabel("FlashBriefing")
191183
.withProperty(DEVICE_PROPERTY_FLASH_BRIEFING_PROFILE, currentFlashBriefingJson)

bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/discovery/FoobotAccountDiscoveryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void deactivate() {
8585
private void addThing(final FoobotDevice foobot) {
8686
logger.debug("Adding new Foobot '{}' with uuid: {}", foobot.getName(), foobot.getUuid());
8787

88-
final ThingUID thingUID = new ThingUID(FoobotBindingConstants.THING_TYPE_FOOBOT, foobot.getUuid());
88+
final ThingUID thingUID = new ThingUID(FoobotBindingConstants.THING_TYPE_FOOBOT, bridgeUID, foobot.getUuid());
8989
final Map<String, Object> properties = new HashMap<>();
9090
properties.put(Thing.PROPERTY_SERIAL_NUMBER, foobot.getUuid());
9191
properties.put(FoobotBindingConstants.CONFIG_UUID, foobot.getUuid());

bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/discovery/GroheOndusDiscoveryService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ protected void startScan() {
7979
ThingUID thingUID = null;
8080
switch (appliance.getType()) {
8181
case org.grohe.ondus.api.model.guard.Appliance.TYPE:
82-
thingUID = new ThingUID(THING_TYPE_SENSEGUARD, appliance.getApplianceId());
82+
thingUID = new ThingUID(THING_TYPE_SENSEGUARD, bridgeUID, appliance.getApplianceId());
8383
break;
8484
case org.grohe.ondus.api.model.sense.Appliance.TYPE:
85-
thingUID = new ThingUID(THING_TYPE_SENSE, appliance.getApplianceId());
85+
thingUID = new ThingUID(THING_TYPE_SENSE, bridgeUID, appliance.getApplianceId());
8686
break;
8787
default:
8888
return;

bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/discovery/HeosPlayerDiscovery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void handleDiscoveredPlayers(Map<Integer, Player> currentPlayers) {
108108
ThingUID bridgeUID = bridge.getThing().getUID();
109109

110110
for (Player player : currentPlayers.values()) {
111-
ThingUID uid = new ThingUID(THING_TYPE_PLAYER, String.valueOf(player.playerId));
111+
ThingUID uid = new ThingUID(THING_TYPE_PLAYER, bridgeUID, String.valueOf(player.playerId));
112112
Map<String, Object> properties = new HashMap<>();
113113
HeosPlayerHandler.propertiesFromPlayer(properties, player);
114114

@@ -162,7 +162,7 @@ private void handleDiscoveredGroups(HashMap<String, Group> currentGroups) {
162162
// Using an unsigned hashCode from the group members to identify
163163
// the group and generates the Thing UID.
164164
// This allows identifying the group even if the sorting within the group has changed
165-
ThingUID uid = new ThingUID(THING_TYPE_GROUP, groupMemberHash);
165+
ThingUID uid = new ThingUID(THING_TYPE_GROUP, bridgeUID, groupMemberHash);
166166
Map<String, Object> properties = new HashMap<>();
167167
properties.put(PROP_NAME, group.name);
168168
properties.put(PROP_GID, group.id);

bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/discovery/InsteonDeviceDiscoveryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void addInsteonDevices(List<String> addresses, ThingUID bridgeUid) {
6060
}
6161

6262
String name = parts[0] + parts[1] + parts[2];
63-
ThingUID uid = new ThingUID(InsteonBindingConstants.DEVICE_THING_TYPE, name);
63+
ThingUID uid = new ThingUID(InsteonBindingConstants.DEVICE_THING_TYPE, bridgeUid, name);
6464
Map<String, Object> properties = new HashMap<>();
6565
properties.put(ADDRESS, address);
6666

bundles/org.openhab.binding.jeelink/src/main/java/org/openhab/binding/jeelink/internal/discovery/SensorDiscoveryService.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,36 @@ public void handleReading(Reading reading) {
102102
|| id.equals(t.getConfiguration().as(JeeLinkSensorConfig.class).sensorId);
103103
}
104104

105+
ThingUID bridgeUID = bridge.getThing().getUID();
106+
105107
if (!sensorThingExists) {
106108
SensorDefinition<?> def = SensorDefinition.getSensorDefinition(reading);
107-
logger.debug("discovery for bridge {} found unknown sensor of type {} with id {}",
108-
bridge.getThing().getUID(), def.getThingTypeUID(), id);
109+
logger.debug("discovery for bridge {} found unknown sensor of type {} with id {}", bridgeUID,
110+
def.getThingTypeUID(), id);
109111

110112
boolean idExists = idExistsAtBridge(id);
111113
String newId = id;
112114

113115
if (idExists) {
114-
logger.debug("bridge {} already has a connected sensor with thing id {}", bridge.getThing().getUID(),
115-
id);
116+
logger.debug("bridge {} already has a connected sensor with thing id {}", bridgeUID, id);
116117

117118
int idx = 1;
118119
while (idExists) {
119120
newId = id + "-" + idx++;
120121
idExists = idExistsAtBridge(newId);
121122
}
122123

123-
logger.debug("Bridge {} uses thing id {} instead of {}", bridge.getThing().getUID(), newId, id);
124+
logger.debug("Bridge {} uses thing id {} instead of {}", bridgeUID, newId, id);
124125
}
125126

126-
ThingUID sensorThing = new ThingUID(def.getThingTypeUID(), newId);
127+
ThingUID sensorThing = new ThingUID(def.getThingTypeUID(), bridgeUID, newId);
127128

128129
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(sensorThing).withLabel(def.getName())
129-
.withBridge(bridge.getThing().getUID()).withRepresentationProperty("id")
130-
.withProperty(PROPERTY_SENSOR_ID, id).build();
130+
.withBridge(bridgeUID).withRepresentationProperty("id").withProperty(PROPERTY_SENSOR_ID, id)
131+
.build();
131132
thingDiscovered(discoveryResult);
132133
} else {
133-
logger.debug("discovery for bridge {} found already known sensor id {}", bridge.getThing().getUID(), id);
134+
logger.debug("discovery for bridge {} found already known sensor id {}", bridgeUID, id);
134135
}
135136
}
136137

bundles/org.openhab.binding.mihome/src/main/java/org/openhab/binding/mihome/internal/discovery/XiaomiItemDiscoveryService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public void onItemUpdate(String sid, String command, JsonObject data) {
105105
Map<String, Object> properties = new HashMap<>(1);
106106
properties.put(ITEM_ID, sid);
107107

108-
ThingUID thingUID = new ThingUID(thingType, sid);
108+
ThingUID bridgeUID = xiaomiBridgeHandler.getThing().getUID();
109+
ThingUID thingUID = new ThingUID(thingType, bridgeUID, sid);
109110

110111
logger.debug("Discovered device - sid: {} model: {}", sid, model);
111112
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withThingType(thingType).withProperties(properties)
112-
.withRepresentationProperty(ITEM_ID).withLabel(modelLabel)
113-
.withBridge(xiaomiBridgeHandler.getThing().getUID()).build());
113+
.withRepresentationProperty(ITEM_ID).withLabel(modelLabel).withBridge(bridgeUID).build());
114114
}
115115
}
116116

bundles/org.openhab.binding.neato/src/main/java/org/openhab/binding/neato/internal/discovery/NeatoAccountDiscoveryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void addThing(Robot robot) {
8787
logger.debug("addThing(): Adding new Neato unit {} to the smarthome inbox", robot.getName());
8888

8989
Map<String, Object> properties = new HashMap<>();
90-
ThingUID thingUID = new ThingUID(NeatoBindingConstants.THING_TYPE_VACUUMCLEANER, robot.getSerial());
90+
ThingUID thingUID = new ThingUID(NeatoBindingConstants.THING_TYPE_VACUUMCLEANER, bridgeUID, robot.getSerial());
9191
properties.put(NeatoBindingConstants.CONFIG_SECRET, robot.getSecretKey());
9292
properties.put(NeatoBindingConstants.CONFIG_SERIAL, robot.getSerial());
9393
properties.put(Thing.PROPERTY_MODEL_ID, robot.getModel());

bundles/org.openhab.binding.openuv/src/main/java/org/openhab/binding/openuv/internal/discovery/OpenUVDiscoveryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ protected void startBackgroundDiscovery() {
9797
}
9898

9999
public void createResults(PointType location) {
100-
ThingUID localOpenUVThing = new ThingUID(LOCATION_REPORT_THING_TYPE, LOCAL);
101100
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
101+
ThingUID localOpenUVThing = new ThingUID(LOCATION_REPORT_THING_TYPE, bridgeUID, LOCAL);
102102
Map<String, Object> properties = new HashMap<>();
103103
properties.put(LOCATION, location.toString());
104104
thingDiscovered(DiscoveryResultBuilder.create(localOpenUVThing).withLabel("Local UV Information")

bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/discovery/VolvoOnCallDiscoveryService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ public void startScan() {
5656
Vehicles vehicle = bridgeHandler.getURL(accountVehicle.vehicleURL, Vehicles.class);
5757
Attributes attributes = bridgeHandler.getURL(Attributes.class, vehicle.vehicleId);
5858

59-
thingDiscovered(
60-
DiscoveryResultBuilder.create(new ThingUID(VEHICLE_THING_TYPE, accountVehicle.vehicleId))
61-
.withLabel(attributes.vehicleType + " " + attributes.registrationNumber)
62-
.withBridge(bridgeHandler.getThing().getUID()).withProperty(VIN, attributes.vin)
63-
.withRepresentationProperty(accountVehicle.vehicleId).build());
59+
thingDiscovered(DiscoveryResultBuilder
60+
.create(new ThingUID(VEHICLE_THING_TYPE, bridgeHandler.getThing().getUID(),
61+
accountVehicle.vehicleId))
62+
.withLabel(attributes.vehicleType + " " + attributes.registrationNumber)
63+
.withBridge(bridgeHandler.getThing().getUID()).withProperty(VIN, attributes.vin)
64+
.withRepresentationProperty(accountVehicle.vehicleId).build());
6465

6566
} catch (VolvoOnCallException e) {
6667
logger.warn("Error while discovering vehicle: {}", e.getMessage());

0 commit comments

Comments
 (0)