Skip to content

Commit

Permalink
[iCloud] Fix things reappearing in inbox (openhab#14661)
Browse files Browse the repository at this point in the history
* Use deviceDiscoveryId instead of id
* Use device display name if discovery id is empty

Signed-off-by: Simon Spielmann <simon.spielmann@gmx.de>
Signed-off-by: Matt Myers <mmyers75@icloud.com>
  • Loading branch information
maihacke authored and matchews committed Aug 9, 2023
1 parent 844baac commit 12c7d23
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,23 @@ public void deviceInformationUpdate(List<ICloudDeviceInformation> deviceInformat
String deviceOwnerName = deviceInformationRecord.getName();

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

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

ThingUID uid = new ThingUID(THING_TYPE_ICLOUDDEVICE, bridgeUID, deviceIdHash);
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withBridge(bridgeUID)
.withProperty(DEVICE_PROPERTY_ID, deviceId)
.withProperty(translatorService.getText(DEVICE_PROPERTY_ID_LABEL), deviceId)
.withProperty(DEVICE_PROPERTY_ID, deviceDiscoveryId)
.withProperty(translatorService.getText(DEVICE_PROPERTY_ID_LABEL), deviceDiscoveryId)
.withProperty(translatorService.getText(DEVICE_PROPERTY_OWNER_LABEL), deviceOwnerName)
.withRepresentationProperty(DEVICE_PROPERTY_ID).withLabel(thingLabel).build();

logger.debug("Device [{}, {}] found.", deviceIdHash, deviceId);
logger.debug("Device [{}, {}] found.", deviceIdHash, deviceDiscoveryId);

thingDiscovered(result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati
this.logger.debug("Device: [{}]", this.deviceId);

for (ICloudDeviceInformation deviceInformationRecord : deviceInformationList) {
String currentId = deviceInformationRecord.getId();

String currentId = deviceInformationRecord.getDeviceDiscoveryId();
if (currentId == null || currentId.isBlank()) {
logger.debug("deviceDiscoveryId is empty, using device name for identification.");
currentId = deviceInformationRecord.getName();
}
logger.debug("Current data element: [id = {}]", currentId);

if (currentId != null && currentId.equals(deviceId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class ICloudDeviceInformation {

private String id;

private String deviceDiscoveryId;

private boolean isLocating;

private boolean isMac;
Expand Down Expand Up @@ -160,6 +162,10 @@ public String getId() {
return this.id;
}

public String getDeviceDiscoveryId() {
return this.deviceDiscoveryId;
}

public boolean getIsLocating() {
return this.isLocating;
}
Expand Down
Loading

0 comments on commit 12c7d23

Please sign in to comment.