mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[hue] Make sure the serial number will be in lowercase (#9367)
* [hue] Make sure the serial number will be in lowercase Necessary for the auto-ignore discovery feature with the representation property. Fix #9364 * Check that the serial number is not null * Check that the serial number is not blank * Build a discovery result even without a serial number Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
133df3aa40
commit
02b356acdf
@ -57,11 +57,18 @@ public class HueBridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
|
||||
properties.put(HOST, device.getDetails().getBaseURL().getHost());
|
||||
properties.put(PORT, device.getDetails().getBaseURL().getPort());
|
||||
properties.put(PROTOCOL, device.getDetails().getBaseURL().getProtocol());
|
||||
properties.put(PROPERTY_SERIAL_NUMBER, device.getDetails().getSerialNumber());
|
||||
String serialNumber = device.getDetails().getSerialNumber();
|
||||
DiscoveryResult result;
|
||||
if (serialNumber != null && !serialNumber.isBlank()) {
|
||||
properties.put(PROPERTY_SERIAL_NUMBER, serialNumber.toLowerCase());
|
||||
|
||||
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
|
||||
.withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(PROPERTY_SERIAL_NUMBER)
|
||||
.build();
|
||||
result = DiscoveryResultBuilder.create(uid).withProperties(properties)
|
||||
.withLabel(device.getDetails().getFriendlyName())
|
||||
.withRepresentationProperty(PROPERTY_SERIAL_NUMBER).build();
|
||||
} else {
|
||||
result = DiscoveryResultBuilder.create(uid).withProperties(properties)
|
||||
.withLabel(device.getDetails().getFriendlyName()).build();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
@ -73,11 +80,12 @@ public class HueBridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
|
||||
DeviceDetails details = device.getDetails();
|
||||
if (details != null) {
|
||||
ModelDetails modelDetails = details.getModelDetails();
|
||||
if (modelDetails != null) {
|
||||
String serialNumber = details.getSerialNumber();
|
||||
if (modelDetails != null && serialNumber != null && !serialNumber.isBlank()) {
|
||||
String modelName = modelDetails.getModelName();
|
||||
if (modelName != null) {
|
||||
if (modelName.startsWith("Philips hue bridge")) {
|
||||
return new ThingUID(THING_TYPE_BRIDGE, details.getSerialNumber());
|
||||
return new ThingUID(THING_TYPE_BRIDGE, serialNumber.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,13 @@ import static org.openhab.binding.hue.internal.HueBindingConstants.*;
|
||||
import static org.openhab.core.thing.Thing.PROPERTY_SERIAL_NUMBER;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -82,6 +88,7 @@ public class HueBridgeNupnpDiscovery extends AbstractDiscoveryService {
|
||||
if (isReachableAndValidHueBridge(bridge)) {
|
||||
String host = bridge.getInternalIpAddress();
|
||||
String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10);
|
||||
serialNumber = serialNumber.toLowerCase();
|
||||
ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
|
||||
DiscoveryResult result = DiscoveryResultBuilder.create(uid)
|
||||
.withProperties(buildProperties(host, serialNumber))
|
||||
|
@ -734,6 +734,7 @@ public class HueBridgeHandler extends ConfigStatusBridgeHandler implements HueCl
|
||||
if (config != null) {
|
||||
Map<String, String> properties = editProperties();
|
||||
String serialNumber = config.getBridgeId().substring(0, 6) + config.getBridgeId().substring(10);
|
||||
serialNumber = serialNumber.toLowerCase();
|
||||
properties.put(PROPERTY_SERIAL_NUMBER, serialNumber);
|
||||
properties.put(PROPERTY_MODEL_ID, config.getModelId());
|
||||
properties.put(PROPERTY_MAC_ADDRESS, config.getMACAddress());
|
||||
|
Loading…
Reference in New Issue
Block a user