From a79b47a2773b7dc0b3bd5018c14aa29350218e59 Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Fri, 24 Mar 2023 08:42:35 +0100 Subject: [PATCH 1/7] Use deviceDiscoveryId instead of id Signed-off-by: Simon Spielmann --- .../internal/discovery/ICloudDeviceDiscovery.java | 10 +++++----- .../icloud/internal/handler/ICloudDeviceHandler.java | 2 +- .../dto/json/response/ICloudDeviceInformation.java | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java index 429795bf584d9..f96abca2991a1 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java @@ -63,19 +63,19 @@ public void deviceInformationUpdate(List deviceInformat String deviceOwnerName = deviceInformationRecord.getName(); String thingLabel = deviceOwnerName + " (" + deviceTypeName + ")"; - String deviceId = deviceInformationRecord.getId(); - String deviceIdHash = Integer.toHexString(deviceId.hashCode()); + String deviceDiscoveryId = deviceInformationRecord.getDeviceDiscoveryId(); + 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); diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java index aa51c597ca5e8..df83ba16ac105 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java @@ -185,7 +185,7 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati this.logger.debug("Device: [{}]", this.deviceId); for (ICloudDeviceInformation deviceInformationRecord : deviceInformationList) { - String currentId = deviceInformationRecord.getId(); + String currentId = deviceInformationRecord.getDeviceDiscoveryId(); logger.debug("Current data element: [id = {}]", currentId); diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/dto/json/response/ICloudDeviceInformation.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/dto/json/response/ICloudDeviceInformation.java index b3a6b8a472ae0..cdbd565342e9e 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/dto/json/response/ICloudDeviceInformation.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/dto/json/response/ICloudDeviceInformation.java @@ -50,6 +50,8 @@ public class ICloudDeviceInformation { private String id; + private String deviceDiscoveryId; + private boolean isLocating; private boolean isMac; @@ -160,6 +162,10 @@ public String getId() { return this.id; } + public String getDeviceDiscoveryId() { + return this.deviceDiscoveryId; + } + public boolean getIsLocating() { return this.isLocating; } From d70dff26482a7c672727b3dc3ffa1bdeb3bfda2b Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Fri, 24 Mar 2023 15:32:48 +0100 Subject: [PATCH 2/7] Use device display name if discovery id is empty Signed-off-by: Simon Spielmann --- .../icloud/internal/discovery/ICloudDeviceDiscovery.java | 4 ++++ .../binding/icloud/internal/handler/ICloudDeviceHandler.java | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java index f96abca2991a1..869b2df355d90 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java @@ -64,6 +64,10 @@ public void deviceInformationUpdate(List deviceInformat String thingLabel = deviceOwnerName + " (" + deviceTypeName + ")"; String deviceDiscoveryId = deviceInformationRecord.getDeviceDiscoveryId(); + if (deviceDiscoveryId == null || "".equals(deviceDiscoveryId)) { + 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()); diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java index df83ba16ac105..ad8e854eed947 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java @@ -186,7 +186,10 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati for (ICloudDeviceInformation deviceInformationRecord : deviceInformationList) { String currentId = deviceInformationRecord.getDeviceDiscoveryId(); - + if (currentId == null || "".equals(currentId)) { + logger.debug("deviceDiscoveryId is empty, using device name for identification."); + currentId = deviceInformationRecord.getDeviceDisplayName(); + } logger.debug("Current data element: [id = {}]", currentId); if (currentId != null && currentId.equals(deviceId)) { From 82b36cd13a8361a5c7ee691f396aef9d0a949b45 Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Wed, 29 Mar 2023 13:27:41 +0200 Subject: [PATCH 3/7] Implement Testcase for discovery Signed-off-by: Simon Spielmann --- .../openhab/binding/icloud/TestICloud.java | 438 ++++++++++++++++++ 1 file changed, 438 insertions(+) diff --git a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java index 126fd8eac46fc..1297f324382af 100644 --- a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java +++ b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java @@ -13,22 +13,45 @@ package org.openhab.binding.icloud; import static org.junit.jupiter.api.Assertions.*; +import static org.openhab.binding.icloud.internal.ICloudBindingConstants.THING_TYPE_ICLOUDDEVICE; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.util.List; +import java.util.Map; import java.util.Scanner; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.openhab.binding.icloud.internal.ICloudApiResponseException; +import org.openhab.binding.icloud.internal.ICloudBindingConstants; import org.openhab.binding.icloud.internal.ICloudService; +import org.openhab.binding.icloud.internal.handler.ICloudDeviceHandler; import org.openhab.binding.icloud.internal.handler.dto.json.response.ICloudAccountDataResponse; import org.openhab.binding.icloud.internal.utilities.JsonUtils; +import org.openhab.core.config.core.ConfigDescription; +import org.openhab.core.config.core.Configuration; import org.openhab.core.storage.json.internal.JsonStorage; +import org.openhab.core.thing.Bridge; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelGroupUID; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingStatus; +import org.openhab.core.thing.ThingStatusInfo; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.thing.binding.ThingHandlerCallback; +import org.openhab.core.thing.binding.builder.ChannelBuilder; +import org.openhab.core.thing.internal.ThingImpl; +import org.openhab.core.thing.type.ChannelGroupTypeUID; +import org.openhab.core.thing.type.ChannelTypeUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,4 +117,419 @@ public void testAuth() throws IOException, InterruptedException, ICloudApiRespon assertNotNull(deviceInfo); stateStorage.flush(); } + + @Test + @EnabledIfSystemProperty(named = "icloud.test.email", matches = ".*", disabledReason = "Only for manual execution.") + public void testDiscovery() { + + String icloudDeviceRespond = """ + { + "userInfo": { + "accountFormatter": 0, + "firstName": "Firstname", + "lastName": "Lastname", + "membersInfo": { + "XXX~": { + "accountFormatter": 0, + "firstName": "Firstname", + "lastName": "Lastname", + "deviceFetchStatus": "LOADING", + "useAuthWidget": true, + "isHSA": true, + "appleId": "dummy@dummy.local" + } + }, + "hasMembers": true + }, + "alert": null, + "serverContext": { + "minCallbackIntervalInMS": 5000, + "preferredLanguage": "de-de", + "enable2FAFamilyActions": false, + "lastSessionExtensionTime": null, + "validRegion": true, + "callbackIntervalInMS": 2000, + "enableMapStats": true, + "timezone": { + "currentOffset": -25200000, + "previousTransition": 1678615199999, + "previousOffset": -28800000, + "tzCurrentName": "Pacific Daylight Time", + "tzName": "America/Los_Angeles" + }, + "authToken": null, + "maxCallbackIntervalInMS": 60000, + "classicUser": false, + "isHSA": true, + "trackInfoCacheDurationInSecs": 86400, + "imageBaseUrl": "https://statici.icloud.com", + "minTrackLocThresholdInMts": 100, + "itemLearnMoreURL": "https://support.apple.com/kb/HT211331?viewlocale=de_DE", + "maxLocatingTime": 90000, + "itemsTabEnabled": true, + "sessionLifespan": 900000, + "info": "", + "prefsUpdateTime": 1679378160178, + "useAuthWidget": true, + "inaccuracyRadiusThreshold": 200, + "clientId": "", + "serverTimestamp": 1679640300550, + "enable2FAFamilyRemove": false, + "deviceImageVersion": "22", + "macCount": 0, + "deviceLoadStatus": "200", + "maxDeviceLoadTime": 60000, + "prsId": 146786264, + "showSllNow": false, + "cloudUser": true, + "enable2FAErase": false + }, + "userPreferences": { + "webPrefs": { + "id": "web_prefs", + "selectedDeviceId": "XXX" + } + }, + "content": [ + { + "msg": null, + "activationLocked": true, + "passcodeLength": 6, + "features": { + "BTR": false, + "LLC": false, + "CLK": false, + "TEU": true, + "SND": true, + "ALS": false, + "CLT": false, + "SVP": false, + "SPN": false, + "XRM": false, + "NWF": true, + "CWP": false, + "MSG": true, + "LOC": true, + "LME": false, + "LMG": false, + "LYU": false, + "LKL": false, + "LST": true, + "LKM": false, + "WMG": true, + "SCA": false, + "PSS": false, + "EAL": false, + "LAE": false, + "PIN": false, + "LCK": true, + "REM": true, + "MCS": false, + "KEY": false, + "KPD": false, + "WIP": true + }, + "scd": false, + "id": "device.id", + "remoteLock": null, + "rm2State": 0, + "modelDisplayName": "iPad", + "fmlyShare": false, + "lostModeCapable": true, + "wipedTimestamp": null, + "encodedDeviceId": null, + "scdPh": "", + "locationCapable": true, + "trackingInfo": null, + "name": "Simon iPad", + "isMac": false, + "thisDevice": false, + "deviceClass": "iPad", + "nwd": false, + "remoteWipe": null, + "canWipeAfterLock": true, + "baUUID": "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", + "lostModeEnabled": false, + "wipeInProgress": false, + "deviceStatus": "200", + "deviceColor": "1-1-0", + "isConsideredAccessory": false, + "deviceWithYou": false, + "lowPowerMode": false, + "rawDeviceModel": "iPad13,1", + "deviceDiscoveryId": "AAAAAAAA-FFFF-FFFF-FFFF-FFFFFFFFFFFF", + "isLocating": true, + "lostTimestamp": "", + "mesg": null, + "batteryLevel": 0.1599999964237213, + "locationEnabled": true, + "lockedTimestamp": null, + "locFoundEnabled": false, + "snd": null, + "lostDevice": null, + "deviceDisplayName": "iPad Air (4th Generation)", + "prsId": null, + "audioChannels": [ + + ], + "batteryStatus": "NotCharging", + "location": { + "isOld": false, + "isInaccurate": false, + "altitude": 0.0, + "positionType": "Unknown", + "secureLocation": null, + "secureLocationTs": 0, + "latitude": 20.00000000000000, + "floorLevel": 0, + "horizontalAccuracy": 1.0, + "locationType": "", + "timeStamp": 1679640074735, + "locationFinished": true, + "verticalAccuracy": 0.0, + "locationMode": null, + "longitude": 10.00000000000000 + }, + "deviceModel": "FourthGen-1-1-0", + "maxMsgChar": 160, + "darkWake": false + }, + { + "msg": null, + "activationLocked": true, + "passcodeLength": 6, + "features": { + "BTR": false, + "LLC": false, + "CLK": false, + "TEU": true, + "SND": true, + "ALS": false, + "CLT": false, + "SVP": false, + "SPN": false, + "XRM": false, + "NWF": true, + "CWP": false, + "MSG": true, + "LOC": true, + "LME": false, + "LMG": false, + "LYU": false, + "LKL": false, + "LST": true, + "LKM": false, + "WMG": true, + "SCA": false, + "PSS": false, + "EAL": false, + "LAE": false, + "PIN": false, + "LCK": true, + "REM": true, + "MCS": false, + "KEY": false, + "KPD": false, + "WIP": true + }, + "scd": false, + "id": "device.id", + "remoteLock": null, + "rm2State": 0, + "modelDisplayName": "iPad", + "fmlyShare": false, + "lostModeCapable": true, + "wipedTimestamp": null, + "encodedDeviceId": null, + "scdPh": "", + "locationCapable": true, + "trackingInfo": null, + "name": "Simon iPad", + "isMac": false, + "thisDevice": false, + "deviceClass": "iPad", + "nwd": false, + "remoteWipe": null, + "canWipeAfterLock": true, + "baUUID": "", + "lostModeEnabled": false, + "wipeInProgress": false, + "deviceStatus": "200", + "deviceColor": "1-1-0", + "isConsideredAccessory": false, + "deviceWithYou": false, + "lowPowerMode": false, + "rawDeviceModel": "iPad13,1", + "deviceDiscoveryId": "", + "isLocating": true, + "lostTimestamp": "", + "mesg": null, + "batteryLevel": 0.1599999964237213, + "locationEnabled": true, + "lockedTimestamp": null, + "locFoundEnabled": false, + "snd": null, + "lostDevice": null, + "deviceDisplayName": "iPad Air without ID", + "prsId": null, + "audioChannels": [ + + ], + "batteryStatus": "NotCharging", + "location": { + "isOld": false, + "isInaccurate": false, + "altitude": 0.0, + "positionType": "Unknown", + "secureLocation": null, + "secureLocationTs": 0, + "latitude": 20.00000000000000, + "floorLevel": 0, + "horizontalAccuracy": 1.0, + "locationType": "", + "timeStamp": 1679640074735, + "locationFinished": true, + "verticalAccuracy": 0.0, + "locationMode": null, + "longitude": 10.00000000000000 + }, + "deviceModel": "FourthGen-1-1-0", + "maxMsgChar": 160, + "darkWake": false + } + ], + "statusCode": "200" + } + """; + ICloudAccountDataResponse deviceInfo = JsonUtils.fromJson(icloudDeviceRespond, ICloudAccountDataResponse.class); + + // Check device with discoveryId + ThingImpl thing = createThing("AAAAAAAA-FFFF-FFFF-FFFF-FFFFFFFFFFFF"); + ICloudDeviceHandler handler = createDeviceHandler(thing); + + handler.deviceInformationUpdate(deviceInfo.getICloudDeviceInformationList()); + + assertEquals(ThingStatus.ONLINE, handler.getThing().getStatus()); + + // Check device without discoveryId + thing = createThing("iPad Air without ID"); + handler = createDeviceHandler(thing); + + handler.deviceInformationUpdate(deviceInfo.getICloudDeviceInformationList()); + + assertEquals(ThingStatus.ONLINE, handler.getThing().getStatus()); + } + + /** + * @return + */ + private ThingImpl createThing(String deviceId) { + String deviceIdHash = Integer.toHexString(deviceId.hashCode()); + + ThingUID uid = new ThingUID(THING_TYPE_ICLOUDDEVICE, "dummyBridgeId", deviceIdHash); + ThingImpl thing = new ThingImpl(THING_TYPE_ICLOUDDEVICE, uid); + thing.getConfiguration().put(ICloudBindingConstants.DEVICE_PROPERTY_ID, deviceId); + return thing; + } + + /** + * @param thing + * @return + */ + private ICloudDeviceHandler createDeviceHandler(ThingImpl thing) { + ICloudDeviceHandler handler = new ICloudDeviceHandler(thing); + handler.setCallback(new ThingHandlerCallback() { + + @Override + public void validateConfigurationParameters(Channel channel, Map configurationParameters) { + // TODO Auto-generated method stub + } + + @Override + public void validateConfigurationParameters(Thing thing, Map configurationParameters) { + // TODO Auto-generated method stub + } + + @Override + public void thingUpdated(Thing thing) { + // TODO Auto-generated method stub + + } + + @Override + public void statusUpdated(Thing thing, ThingStatusInfo thingStatus) { + thing.setStatusInfo(thingStatus); + } + + @Override + public void stateUpdated(ChannelUID channelUID, State state) { + // TODO Auto-generated method stub + } + + @Override + public void postCommand(ChannelUID channelUID, Command command) { + // TODO Auto-generated method stub + } + + @Override + public void migrateThingType(Thing thing, ThingTypeUID thingTypeUID, Configuration configuration) { + // TODO Auto-generated method stub + } + + @Override + public boolean isChannelLinked(ChannelUID channelUID) { + // TODO Auto-generated method stub + return false; + } + + @Override + public @Nullable ConfigDescription getConfigDescription(ThingTypeUID thingTypeUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public @Nullable ConfigDescription getConfigDescription(ChannelTypeUID channelTypeUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public @Nullable Bridge getBridge(ThingUID bridgeUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ChannelBuilder editChannel(Thing thing, ChannelUID channelUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List createChannelBuilders(ChannelGroupUID channelGroupUID, + ChannelGroupTypeUID channelGroupTypeUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelTypeUID channelTypeUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void configurationUpdated(Thing thing) { + // TODO Auto-generated method stub + } + + @Override + public void channelTriggered(Thing thing, ChannelUID channelUID, String event) { + // TODO Auto-generated method stub + } + }); + handler.initialize(); + return handler; + } } From 12994ac570640b9cd95cbd4e3d8ea58b30744c2f Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Thu, 30 Mar 2023 08:26:35 +0200 Subject: [PATCH 4/7] Fix usage of device name Signed-off-by: Simon Spielmann --- .../icloud/internal/handler/ICloudDeviceHandler.java | 2 +- .../test/java/org/openhab/binding/icloud/TestICloud.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java index ad8e854eed947..b3d2190a44f92 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java @@ -188,7 +188,7 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati String currentId = deviceInformationRecord.getDeviceDiscoveryId(); if (currentId == null || "".equals(currentId)) { logger.debug("deviceDiscoveryId is empty, using device name for identification."); - currentId = deviceInformationRecord.getDeviceDisplayName(); + currentId = deviceInformationRecord.getName(); } logger.debug("Current data element: [id = {}]", currentId); diff --git a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java index 1297f324382af..92ca8f43cf314 100644 --- a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java +++ b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java @@ -241,7 +241,7 @@ public void testDiscovery() { "scdPh": "", "locationCapable": true, "trackingInfo": null, - "name": "Simon iPad", + "name": "My iPad", "isMac": false, "thisDevice": false, "deviceClass": "iPad", @@ -344,7 +344,7 @@ public void testDiscovery() { "scdPh": "", "locationCapable": true, "trackingInfo": null, - "name": "Simon iPad", + "name": "iPad Air without ID", "isMac": false, "thisDevice": false, "deviceClass": "iPad", @@ -370,7 +370,7 @@ public void testDiscovery() { "locFoundEnabled": false, "snd": null, "lostDevice": null, - "deviceDisplayName": "iPad Air without ID", + "deviceDisplayName": "iPad", "prsId": null, "audioChannels": [ From fbf71724a360e0bb8bb7555e1246b2711e069059 Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Thu, 30 Mar 2023 10:15:25 +0200 Subject: [PATCH 5/7] Fix spotless Signed-off-by: Simon Spielmann --- .../src/test/java/org/openhab/binding/icloud/TestICloud.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java index 92ca8f43cf314..847e434e19845 100644 --- a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java +++ b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java @@ -453,7 +453,6 @@ public void validateConfigurationParameters(Thing thing, Map con @Override public void thingUpdated(Thing thing) { // TODO Auto-generated method stub - } @Override From 5a4482330bf203d55fec72787050b3594e1819d1 Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Thu, 30 Mar 2023 11:42:19 +0200 Subject: [PATCH 6/7] Code style: Non Null fixed Signed-off-by: Simon Spielmann --- .../openhab/binding/icloud/TestICloud.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java index 847e434e19845..da9af630ca260 100644 --- a/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java +++ b/bundles/org.openhab.binding.icloud/src/test/java/org/openhab/binding/icloud/TestICloud.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Scanner; @@ -442,17 +443,14 @@ private ICloudDeviceHandler createDeviceHandler(ThingImpl thing) { @Override public void validateConfigurationParameters(Channel channel, Map configurationParameters) { - // TODO Auto-generated method stub } @Override public void validateConfigurationParameters(Thing thing, Map configurationParameters) { - // TODO Auto-generated method stub } @Override public void thingUpdated(Thing thing) { - // TODO Auto-generated method stub } @Override @@ -462,70 +460,58 @@ public void statusUpdated(Thing thing, ThingStatusInfo thingStatus) { @Override public void stateUpdated(ChannelUID channelUID, State state) { - // TODO Auto-generated method stub } @Override public void postCommand(ChannelUID channelUID, Command command) { - // TODO Auto-generated method stub } @Override public void migrateThingType(Thing thing, ThingTypeUID thingTypeUID, Configuration configuration) { - // TODO Auto-generated method stub } @Override public boolean isChannelLinked(ChannelUID channelUID) { - // TODO Auto-generated method stub return false; } @Override public @Nullable ConfigDescription getConfigDescription(ThingTypeUID thingTypeUID) { - // TODO Auto-generated method stub return null; } @Override public @Nullable ConfigDescription getConfigDescription(ChannelTypeUID channelTypeUID) { - // TODO Auto-generated method stub return null; } @Override public @Nullable Bridge getBridge(ThingUID bridgeUID) { - // TODO Auto-generated method stub return null; } @Override public ChannelBuilder editChannel(Thing thing, ChannelUID channelUID) { - // TODO Auto-generated method stub - return null; + return ChannelBuilder.create(channelUID); // dummy implementation, probably won't work. } @Override public List createChannelBuilders(ChannelGroupUID channelGroupUID, ChannelGroupTypeUID channelGroupTypeUID) { - // TODO Auto-generated method stub - return null; + return new ArrayList(); // dummy implementation, probably won't work. } @Override public ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelTypeUID channelTypeUID) { - // TODO Auto-generated method stub - return null; + return ChannelBuilder.create(channelUID); // dummy implementation, probably won't work. } @Override public void configurationUpdated(Thing thing) { - // TODO Auto-generated method stub } @Override public void channelTriggered(Thing thing, ChannelUID channelUID, String event) { - // TODO Auto-generated method stub } }); handler.initialize(); From 91117e81b9950af0a10457fecacf84cdf4935e6c Mon Sep 17 00:00:00 2001 From: Simon Spielmann Date: Fri, 28 Apr 2023 14:44:43 +0200 Subject: [PATCH 7/7] Change blank id (incorporate code review) Signed-off-by: Simon Spielmann --- .../icloud/internal/discovery/ICloudDeviceDiscovery.java | 2 +- .../binding/icloud/internal/handler/ICloudDeviceHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java index 869b2df355d90..82e6f12a7aeaf 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/discovery/ICloudDeviceDiscovery.java @@ -64,7 +64,7 @@ public void deviceInformationUpdate(List deviceInformat String thingLabel = deviceOwnerName + " (" + deviceTypeName + ")"; String deviceDiscoveryId = deviceInformationRecord.getDeviceDiscoveryId(); - if (deviceDiscoveryId == null || "".equals(deviceDiscoveryId)) { + if (deviceDiscoveryId == null || deviceDiscoveryId.isBlank()) { logger.debug("deviceDiscoveryId is empty, using device name for identification."); deviceDiscoveryId = deviceOwnerName; } diff --git a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java index b3d2190a44f92..30e9aa8f9344f 100644 --- a/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java +++ b/bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/handler/ICloudDeviceHandler.java @@ -186,7 +186,7 @@ private void updateLocationRelatedStates(ICloudDeviceInformation deviceInformati for (ICloudDeviceInformation deviceInformationRecord : deviceInformationList) { String currentId = deviceInformationRecord.getDeviceDiscoveryId(); - if (currentId == null || "".equals(currentId)) { + if (currentId == null || currentId.isBlank()) { logger.debug("deviceDiscoveryId is empty, using device name for identification."); currentId = deviceInformationRecord.getName(); }