Skip to content

Commit 8e5b59f

Browse files
committed
fix property and capability handling
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
1 parent 8633d44 commit 8e5b59f

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

bundles/org.openhab.binding.dirigera/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
24

35
<modelVersion>4.0.0</modelVersion>
46

bundles/org.openhab.binding.dirigera/src/main/java/org/openhab/binding/dirigera/internal/handler/BaseHandler.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
218218
protected void updateProperties() {
219219
// fill canSend and canReceive capabilities
220220
Map<String, Object> modelProperties = gateway().model().getPropertiesFor(config.id);
221+
addCapabilities(config.id);
222+
TreeMap<String, String> handlerProperties = new TreeMap<>(editProperties());
223+
modelProperties.forEach((key, value) -> {
224+
handlerProperties.put(key, value.toString());
225+
});
226+
updateProperties(handlerProperties);
227+
}
228+
229+
protected void addCapabilities(String id) {
230+
Map<String, Object> modelProperties = gateway().model().getPropertiesFor(id);
221231
Object canReceiveCapabilities = modelProperties.get(CAPABILITIES_KEY_CAN_RECEIVE);
222232
if (canReceiveCapabilities instanceof JSONArray jsonArray) {
223233
jsonArray.forEach(capability -> {
@@ -234,12 +244,6 @@ protected void updateProperties() {
234244
}
235245
});
236246
}
237-
238-
TreeMap<String, String> handlerProperties = new TreeMap<>(editProperties());
239-
modelProperties.forEach((key, value) -> {
240-
handlerProperties.put(key, value.toString());
241-
});
242-
updateProperties(handlerProperties);
243247
}
244248

245249
/**

bundles/org.openhab.binding.dirigera/src/main/java/org/openhab/binding/dirigera/internal/handler/light/LightSetHandler.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.List;
2020
import java.util.Map;
21+
import java.util.TreeMap;
2122
import java.util.concurrent.ConcurrentHashMap;
2223

2324
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -81,7 +82,26 @@ public void initializeDevice() {
8182
memberReachability.clear();
8283
memberDeviceIds.forEach(id -> memberReachability.put(id, false));
8384

84-
updateProperties();
85+
// special handling for device set properties - add for each device in set their individual canReceive and
86+
// canSend properties
87+
receiveCapabilities.clear();
88+
sendCapabilities.clear();
89+
memberDeviceIds.forEach(id -> {
90+
Map<String, Object> modelProperties = gateway().model().getPropertiesFor(id);
91+
Object customName = gateway().model().getCustonNameFor(id);
92+
93+
TreeMap<String, String> handlerProperties = new TreeMap<>(editProperties());
94+
Object receiveCapabilities = modelProperties.get(CAPABILITIES_KEY_CAN_RECEIVE);
95+
handlerProperties.put(customName + " " + CAPABILITIES_KEY_CAN_RECEIVE,
96+
receiveCapabilities != null ? receiveCapabilities.toString() : "[]");
97+
Object sendCapabilities = modelProperties.get(CAPABILITIES_KEY_CAN_SEND);
98+
handlerProperties.put(customName + " " + CAPABILITIES_KEY_CAN_SEND,
99+
sendCapabilities != null ? sendCapabilities.toString() : "[]");
100+
updateProperties(handlerProperties);
101+
// properties updated and user is able to check all devices in the set and their capabilities, now add the
102+
// capabilities to the set itself
103+
addCapabilities(id);
104+
});
85105

86106
// 2) Initialize the set's own customName from the model so that subsequent member
87107
// updates (which carry the member's own customName) cannot overwrite it.

0 commit comments

Comments
 (0)