diff --git a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/ConfigStore.java b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/ConfigStore.java index 7ec3261b5c382..e9f560eaf406e 100644 --- a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/ConfigStore.java +++ b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/ConfigStore.java @@ -122,8 +122,6 @@ public class ConfigStore { private int highestAssignedHueID = 1; - private String hueIDPrefix = ""; - public ConfigStore() { scheduler = ThreadPoolManager.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON); } @@ -236,8 +234,6 @@ public void modified(Map properties) { ds.config.bridgeid = ds.config.bridgeid.substring(0, 12); } - hueIDPrefix = getHueIDPrefixFromUUID(config.uuid); - if (config.permanentV1bridge) { ds.config.makeV1bridge(); } @@ -263,31 +259,6 @@ private String getConfiguredHostAddress(InetAddress configuredAddress) { } } - /** - * Get the prefix used to create a unique id - * - * @param uuid The uuid - * @return The prefix in the format of AA:BB:CC:DD:EE:FF:00:11 if uuid is a valid UUID, otherwise uuid is returned. - */ - private String getHueIDPrefixFromUUID(final String uuid) { - // Hue API example of a unique id is AA:BB:CC:DD:EE:FF:00:11-XX - // 00:11-XX is generated from the item. - String prefix = uuid; - try { - // Generate prefix if uuid is a randomly generated UUID - if (UUID.fromString(uuid).version() == 4) { - final StringBuilder sb = new StringBuilder(17); - sb.append(uuid, 0, 2).append(":").append(uuid, 2, 4).append(":").append(uuid, 4, 6).append(":") - .append(uuid, 6, 8).append(":").append(uuid, 9, 11).append(":").append(uuid, 11, 13); - prefix = sb.toString().toUpperCase(); - } - } catch (final IllegalArgumentException e) { - // uuid is not a valid UUID - } - - return prefix; - } - @Deactivate public void deactive(int reason) { ScheduledFuture future = pairingOffFuture; @@ -351,17 +322,26 @@ public String mapItemUIDtoHueID(Item item) { * @return The unique id */ public String getHueUniqueId(final String hueId) { + // From the Hue API: + // Format: AA:BB:CC:DD:EE:FF:00:11-XX + // Content: Device MAC + unique endpoint id + // Example: 00:17:88:01:00:bd:c7:b9-0b + // Using the item's hueID for every three octets ensures both the MAC and + // endpoint are unique for each item which seems important for Alexa discovery. String unique; try { - final String id = String.format("%06X", Integer.valueOf(hueId)); + final String id = String.format("%06x", Integer.valueOf(hueId)); final StringBuilder sb = new StringBuilder(26); - sb.append(hueIDPrefix).append(":").append(id, 0, 2).append(":").append(id, 2, 4).append("-").append(id, 4, - 6); + + sb.append(id, 0, 2).append(":").append(id, 2, 4).append(":").append(id, 4, 6).append(":")// + .append(id, 0, 2).append(":").append(id, 2, 4).append(":").append(id, 4, 6).append(":")// + .append(id, 0, 2).append(":").append(id, 2, 4).append("-").append(id, 4, 6); + unique = sb.toString(); } catch (final NumberFormatException | IllegalFormatException e) { // Use the hueId as is - unique = hueIDPrefix + "-" + hueId; + unique = hueId; } return unique; diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ItemUIDtoHueIDMappingTests.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ItemUIDtoHueIDMappingTests.java index 3385015a2d40a..41303755b8502 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ItemUIDtoHueIDMappingTests.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ItemUIDtoHueIDMappingTests.java @@ -133,7 +133,7 @@ public void uniqueIdForLargeHueID() { HueLightEntry device = cs.ds.lights.get(hueID); assertThat(device.item, is(item)); assertThat(device.state, is(instanceOf(HueStatePlug.class))); - assertThat(device.uniqueid, CoreMatchers.is("A6:68:DC:9B:71:72:00:00-FF")); + assertThat(device.uniqueid, CoreMatchers.is("00:00:ff:00:00:ff:00:00-ff")); item = new SwitchItem("switch2"); item.setCategory("Light"); @@ -146,6 +146,6 @@ public void uniqueIdForLargeHueID() { device = cs.ds.lights.get(hueID); assertThat(device.item, is(item)); assertThat(device.state, is(instanceOf(HueStatePlug.class))); - assertThat(device.uniqueid, CoreMatchers.is("A6:68:DC:9B:71:72:03:E8-00")); + assertThat(device.uniqueid, CoreMatchers.is("03:e8:00:03:e8:00:03:e8-00")); } }