[satel] Thing discovery fix (#9718)

Signed-off-by: Krzysztof Goworek <krzysztof.goworek@gmail.com>
pull/9819/head
druciak 2021-01-13 22:16:34 +01:00 committed by GitHub
parent ec1a91c6d7
commit 8616c72ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 17 deletions

View File

@ -289,7 +289,7 @@ The result of this action is compatible with channels of `event-log` thing and c
Usage: Usage:
``` ```
val actions = getActions("satel", "satel:event-log:home") val actions = getActions("satel", "satel:event-log:home:EventLog")
val eventRec = actions.readEvent(-1) val eventRec = actions.readEvent(-1)
logInfo("EventLog", eventRec.get("description")) logInfo("EventLog", eventRec.get("description"))
``` ```
@ -309,9 +309,9 @@ Bridge satel:ethm-1:home [ host="192.168.0.2", refresh=1000, userCode="1234", en
Thing shutter KitchenWindow [ upId=2, downId=3 ] Thing shutter KitchenWindow [ upId=2, downId=3 ]
Thing output Siren [ id=17, wireless=true ] Thing output Siren [ id=17, wireless=true ]
Thing atd-100 KitchenTemp [ id=10, refresh=30 ] Thing atd-100 KitchenTemp [ id=10, refresh=30 ]
Thing system System []
Thing event-log EventLog []
} }
Thing satel:system:home "System" (satel:ethm-1:home) []
Thing satel:event-log:home "Event log" (satel:ethm-1:home) []
``` ```
@ -328,9 +328,9 @@ Switch BEDROOM_TAMPER "Bedroom PIR tampered" (Satel) { channel="satel:zone:home:
Switch BEDROOM_TAMPER_M "Bedroom PIR tamper memory" (Satel) { channel="satel:zone:home:BedroomPIR:tamper_alarm_memory" } Switch BEDROOM_TAMPER_M "Bedroom PIR tamper memory" (Satel) { channel="satel:zone:home:BedroomPIR:tamper_alarm_memory" }
Switch KITCHEN_LAMP "Kitchen lamp" (Satel) { channel="satel:output:home:KitchenLamp:state" } Switch KITCHEN_LAMP "Kitchen lamp" (Satel) { channel="satel:output:home:KitchenLamp:state" }
Rollershutter KITCHEN_BLIND "Kitchen blind" (Satel) { channel="satel:shutter:home:KitchenWindow:shutter_state" } Rollershutter KITCHEN_BLIND "Kitchen blind" (Satel) { channel="satel:shutter:home:KitchenWindow:shutter_state" }
Switch SYSTEM_TROUBLES "Troubles in the system" (Satel) { channel="satel:system:home:troubles" } Switch SYSTEM_TROUBLES "Troubles in the system" (Satel) { channel="satel:system:home:System:troubles" }
String KEYPAD_CHAR ">" <none> (Satel) String KEYPAD_CHAR ">" <none> (Satel)
String USER_CODE "User code" (Satel) { channel="satel:system:home:user_code" } String USER_CODE "User code" (Satel) { channel="satel:system:home:System:user_code" }
Switch SIREN_LOBATT "Siren: low battery level" (Satel) { channel="satel:output:home:Siren:device_lobatt" } Switch SIREN_LOBATT "Siren: low battery level" (Satel) { channel="satel:output:home:Siren:device_lobatt" }
Switch SIREN_NOCOMM "Siren: no communication" (Satel) { channel="satel:output:home:Siren:device_nocomm" } Switch SIREN_NOCOMM "Siren: no communication" (Satel) { channel="satel:output:home:Siren:device_nocomm" }
Number:Temperature KITCHEN_TEMP "Kitchen temperature [%.1f °C]" <temperature> (Satel) { channel="satel:atd-100:home:KitchenTemp:temperature" } Number:Temperature KITCHEN_TEMP "Kitchen temperature [%.1f °C]" <temperature> (Satel) { channel="satel:atd-100:home:KitchenTemp:temperature" }
@ -380,7 +380,7 @@ rule "Keypad char entered"
when when
Item KEYPAD_CHAR changed Item KEYPAD_CHAR changed
then then
val org.joda.time.DateTime timeout = now.plusSeconds(20) val timeout = now.plusSeconds(20)
if (KEYPAD_CHAR.state == "-") { if (KEYPAD_CHAR.state == "-") {
logInfo("Keypad", "Changing user code") logInfo("Keypad", "Changing user code")
@ -414,7 +414,7 @@ rule "Send event log"
when when
Item Alarms changed to ON Item Alarms changed to ON
then then
val actions = getActions("satel", "satel:event-log:home") val actions = getActions("satel", "satel:event-log:home:EventLog")
if (null === actions) { if (null === actions) {
logInfo("EventLog", "Actions not found, check thing ID") logInfo("EventLog", "Actions not found, check thing ID")
return return

View File

@ -80,8 +80,6 @@ public class SatelHandlerFactory extends BaseThingHandlerFactory {
if (effectiveUID == null) { if (effectiveUID == null) {
if (DEVICE_THING_TYPES_UIDS.contains(thingTypeUID)) { if (DEVICE_THING_TYPES_UIDS.contains(thingTypeUID)) {
effectiveUID = getDeviceUID(thingTypeUID, thingUID, configuration, bridgeUID); 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); return super.createThing(thingTypeUID, configuration, effectiveUID, bridgeUID);

View File

@ -152,14 +152,10 @@ public class SatelDeviceDiscoveryService extends AbstractDiscoveryService {
private void addThing(ThingTypeUID thingTypeUID, @Nullable String deviceId, String label, private void addThing(ThingTypeUID thingTypeUID, @Nullable String deviceId, String label,
Map<String, Object> properties) { Map<String, Object> properties) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID(); final ThingUID bridgeUID = bridgeHandler.getThing().getUID();
ThingUID thingUID; final ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID,
if (deviceId == null) { deviceId == null ? toCamelCase(thingTypeUID.getId()) : deviceId);
thingUID = new ThingUID(thingTypeUID, bridgeUID.getId()); final DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID)
} else {
thingUID = new ThingUID(thingTypeUID, bridgeUID, deviceId);
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID)
.withBridge(bridgeUID).withLabel(label).withProperties(properties).build(); .withBridge(bridgeUID).withLabel(label).withProperties(properties).build();
thingDiscovered(discoveryResult); thingDiscovered(discoveryResult);
} }
@ -193,4 +189,19 @@ public class SatelDeviceDiscoveryService extends AbstractDiscoveryService {
return false; 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();
}
} }