Skip to content

Commit 67f1a80

Browse files
authored
[iCloud] Fix things reappearing in inbox (openhab#14661)
* Use deviceDiscoveryId instead of id * Use device display name if discovery id is empty Signed-off-by: Simon Spielmann <[email protected]>
1 parent dc5d76d commit 67f1a80

File tree

4 files changed

+443
-7
lines changed

4 files changed

+443
-7
lines changed

bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@ public void deviceInformationUpdate(List<ICloudDeviceInformation> deviceInformat
6363
String deviceOwnerName = deviceInformationRecord.getName();
6464

6565
String thingLabel = deviceOwnerName + " (" + deviceTypeName + ")";
66-
String deviceId = deviceInformationRecord.getId();
67-
String deviceIdHash = Integer.toHexString(deviceId.hashCode());
66+
String deviceDiscoveryId = deviceInformationRecord.getDeviceDiscoveryId();
67+
if (deviceDiscoveryId == null || deviceDiscoveryId.isBlank()) {
68+
logger.debug("deviceDiscoveryId is empty, using device name for identification.");
69+
deviceDiscoveryId = deviceOwnerName;
70+
}
71+
String deviceIdHash = Integer.toHexString(deviceDiscoveryId.hashCode());
6872

6973
logger.debug("iCloud device discovery for [{}]", deviceInformationRecord.getDeviceDisplayName());
7074

7175
ThingUID uid = new ThingUID(THING_TYPE_ICLOUDDEVICE, bridgeUID, deviceIdHash);
7276
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withBridge(bridgeUID)
73-
.withProperty(DEVICE_PROPERTY_ID, deviceId)
74-
.withProperty(translatorService.getText(DEVICE_PROPERTY_ID_LABEL), deviceId)
77+
.withProperty(DEVICE_PROPERTY_ID, deviceDiscoveryId)
78+
.withProperty(translatorService.getText(DEVICE_PROPERTY_ID_LABEL), deviceDiscoveryId)
7579
.withProperty(translatorService.getText(DEVICE_PROPERTY_OWNER_LABEL), deviceOwnerName)
7680
.withRepresentationProperty(DEVICE_PROPERTY_ID).withLabel(thingLabel).build();
7781

78-
logger.debug("Device [{}, {}] found.", deviceIdHash, deviceId);
82+
logger.debug("Device [{}, {}] found.", deviceIdHash, deviceDiscoveryId);
7983

8084
thingDiscovered(result);
8185

bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati
185185
this.logger.debug("Device: [{}]", this.deviceId);
186186

187187
for (ICloudDeviceInformation deviceInformationRecord : deviceInformationList) {
188-
String currentId = deviceInformationRecord.getId();
189-
188+
String currentId = deviceInformationRecord.getDeviceDiscoveryId();
189+
if (currentId == null || currentId.isBlank()) {
190+
logger.debug("deviceDiscoveryId is empty, using device name for identification.");
191+
currentId = deviceInformationRecord.getName();
192+
}
190193
logger.debug("Current data element: [id = {}]", currentId);
191194

192195
if (currentId != null && currentId.equals(deviceId)) {

bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/dto/json/response/ICloudDeviceInformation.java

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class ICloudDeviceInformation {
5050

5151
private String id;
5252

53+
private String deviceDiscoveryId;
54+
5355
private boolean isLocating;
5456

5557
private boolean isMac;
@@ -160,6 +162,10 @@ public String getId() {
160162
return this.id;
161163
}
162164

165+
public String getDeviceDiscoveryId() {
166+
return this.deviceDiscoveryId;
167+
}
168+
163169
public boolean getIsLocating() {
164170
return this.isLocating;
165171
}

0 commit comments

Comments
 (0)