[satel] Thing discovery fix (#9718)
Signed-off-by: Krzysztof Goworek <krzysztof.goworek@gmail.com>
This commit is contained in:
@@ -80,8 +80,6 @@ public class SatelHandlerFactory extends BaseThingHandlerFactory {
|
||||
if (effectiveUID == null) {
|
||||
if (DEVICE_THING_TYPES_UIDS.contains(thingTypeUID)) {
|
||||
effectiveUID = getDeviceUID(thingTypeUID, thingUID, configuration, bridgeUID);
|
||||
} else if (VIRTUAL_THING_TYPES_UIDS.contains(thingTypeUID) && bridgeUID != null) {
|
||||
effectiveUID = new ThingUID(thingTypeUID, bridgeUID.getId());
|
||||
}
|
||||
}
|
||||
return super.createThing(thingTypeUID, configuration, effectiveUID, bridgeUID);
|
||||
|
||||
@@ -152,14 +152,10 @@ public class SatelDeviceDiscoveryService extends AbstractDiscoveryService {
|
||||
|
||||
private void addThing(ThingTypeUID thingTypeUID, @Nullable String deviceId, String label,
|
||||
Map<String, Object> properties) {
|
||||
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
|
||||
ThingUID thingUID;
|
||||
if (deviceId == null) {
|
||||
thingUID = new ThingUID(thingTypeUID, bridgeUID.getId());
|
||||
} else {
|
||||
thingUID = new ThingUID(thingTypeUID, bridgeUID, deviceId);
|
||||
}
|
||||
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID)
|
||||
final ThingUID bridgeUID = bridgeHandler.getThing().getUID();
|
||||
final ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID,
|
||||
deviceId == null ? toCamelCase(thingTypeUID.getId()) : deviceId);
|
||||
final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID)
|
||||
.withBridge(bridgeUID).withLabel(label).withProperties(properties).build();
|
||||
thingDiscovered(discoveryResult);
|
||||
}
|
||||
@@ -193,4 +189,19 @@ public class SatelDeviceDiscoveryService extends AbstractDiscoveryService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String toCamelCase(String s) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean makeUpper = true;
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '-') {
|
||||
makeUpper = true;
|
||||
} else {
|
||||
result.append(makeUpper ? Character.toUpperCase(c) : c);
|
||||
makeUpper = false;
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user