Skip to content

Commit aa2d136

Browse files
committed
Fix NPE
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
1 parent d678960 commit aa2d136

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ protected void unregisterDevice(String ownId) {
436436
* @param ownId the device OpenWebNet id
437437
* @return the registered device Thing handler or null if the id cannot be found
438438
*/
439-
public @Nullable OpenWebNetThingHandler getRegisteredDevice(@Nullable String ownId) {
439+
public @Nullable OpenWebNetThingHandler getRegisteredDevice(String ownId) {
440440
return registeredDevices.get(ownId);
441441
}
442442

bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetLightingHandler.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -255,33 +255,43 @@ protected Who getManagedWho() {
255255
return Who.LIGHTING;
256256
}
257257

258+
/**
259+
* Handles incoming OpenWebNet messages for this lighting device.
260+
* This method processes lighting state changes and propagates APL (Area/Point Light) messages
261+
* to appropriate group handlers for hierarchical control.
262+
*
263+
* @param msg the OpenWebNet message to handle (should be a Lighting message)
264+
*/
258265
@Override
259266
protected void handleMessage(BaseOpenMessage msg) {
260267
logger.debug("handleMessage({}) for thing: {}", msg, thing.getUID());
261268
super.handleMessage(msg);
262269

270+
// Update device state based on thing type - dimmers handle brightness, switches handle on/off
263271
ThingTypeUID thingType = thing.getThingTypeUID();
264272
if (THING_TYPE_ZB_DIMMER.equals(thingType) || THING_TYPE_BUS_DIMMER.equals(thingType)) {
265273
updateBrightness((Lighting) msg);
266274
} else {
267275
updateOnOffState((Lighting) msg);
268276
}
269277

278+
// Handle APL (Area/Point Light) message propagation for BUS gateway devices
279+
// APL messages need to be forwarded to area and general handlers for group control
270280
OpenWebNetBridgeHandler bridgeHandler = this.bridgeHandler;
271281
if (bridgeHandler != null && bridgeHandler.isBusGateway()) {
272282
if (deviceWhere instanceof WhereLightAutom whereLightAutom && ownId != null && whereLightAutom.isAPL()) {
273-
// Propagate APL msg to AREA handler, if exists
274-
OpenWebNetLightingGroupHandler areaHandler = (OpenWebNetLightingGroupHandler) bridgeHandler
275-
.getRegisteredDevice(areaOwnId);
276-
if (areaHandler != null) {
283+
284+
// First try to propagate to AREA handler (e.g., "1.1" -> area handler for area 1)
285+
String areaOwnId = this.areaOwnId;
286+
if (areaOwnId != null && bridgeHandler
287+
.getRegisteredDevice(areaOwnId) instanceof OpenWebNetLightingGroupHandler areaHandler) {
277288
logger.debug("Light {} is propagating msg {} to AREA handler {}", whereLightAutom, msg, areaOwnId);
278289
areaHandler.handlePropagatedMessage((Lighting) msg, this.ownId);
279290
} else {
280-
// Propagate APL msg to GEN handler, if exists
291+
// If no area handler exists, try to propagate to GEN (general) handler (e.g., "1.0")
281292
String genOwnId = this.getManagedWho().value() + ".0";
282-
OpenWebNetLightingGroupHandler genHandler = (OpenWebNetLightingGroupHandler) bridgeHandler
283-
.getRegisteredDevice(genOwnId);
284-
if (genHandler != null) {
293+
if (bridgeHandler
294+
.getRegisteredDevice(genOwnId) instanceof OpenWebNetLightingGroupHandler genHandler) {
285295
logger.debug("Light {} is propagating msg {} to GEN handler", whereLightAutom, msg);
286296
genHandler.handlePropagatedMessage((Lighting) msg, this.ownId);
287297
}
@@ -466,19 +476,17 @@ public void dispose() {
466476
OpenWebNetBridgeHandler bridgeHandler = this.bridgeHandler;
467477
if (deviceWhere instanceof WhereLightAutom whereLightAutom && bridgeHandler != null
468478
&& bridgeHandler.isBusGateway()) {
469-
int area = whereLightAutom.getArea();
470-
if (areaOwnId != null) {
479+
String areaOwnId = this.areaOwnId;
480+
if (areaOwnId != null && bridgeHandler
481+
.getRegisteredDevice(areaOwnId) instanceof OpenWebNetLightingGroupHandler areaHandler) {
471482
// remove light from listOn for Area
472-
OpenWebNetLightingGroupHandler areaHandler = (OpenWebNetLightingGroupHandler) bridgeHandler
473-
.getRegisteredDevice(areaOwnId);
474-
if (areaHandler != null) {
475-
if (areaHandler.listOn.remove(ownId)) {
476-
logger.debug("Removed {} from listOn for {}", ownId, areaOwnId);
477-
}
483+
484+
if (areaHandler.listOn.remove(ownId)) {
485+
logger.debug("Removed {} from listOn for {}", ownId, areaOwnId);
478486
}
479487
}
480488
// remove light from lightsMap
481-
bridgeHandler.removeLight(area, this);
489+
bridgeHandler.removeLight(whereLightAutom.getArea(), this);
482490
}
483491
super.dispose();
484492
}

0 commit comments

Comments
 (0)