From 2184c2b21a99f5b455f9fdc3403e2d569a10e675 Mon Sep 17 00:00:00 2001 From: Lars Finander Date: Wed, 24 Feb 2016 09:20:41 -0800 Subject: [PATCH] DVCSMP-1517 Wemo (Connect) SmartApp throws NPE -Wemo (Connect) SmartApp throws NPE when trying to call subscribe on null object --- .../wemo-connect.src/wemo-connect.groovy | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/smartapps/smartthings/wemo-connect.src/wemo-connect.groovy b/smartapps/smartthings/wemo-connect.src/wemo-connect.groovy index 0002c37..6213f7b 100644 --- a/smartapps/smartthings/wemo-connect.src/wemo-connect.groovy +++ b/smartapps/smartthings/wemo-connect.src/wemo-connect.groovy @@ -341,8 +341,12 @@ def ssdpSwitchHandler(evt) { deviceChangedValues = true log.debug "Device's port or ip changed..." def child = getChildDevice(parsedEvent.mac) - child.subscribe(parsedEvent.ip, parsedEvent.port) - child.poll() + if (child) { + child.subscribe(parsedEvent.ip, parsedEvent.port) + child.poll() + } else { + log.debug "Device with mac $parsedEvent.mac not found" + } } } } @@ -410,8 +414,12 @@ def ssdpLightSwitchHandler(evt) { deviceChangedValues = true log.debug "Device's port or ip changed..." def child = getChildDevice(parsedEvent.mac) - log.debug "updating ip and port, and resubscribing, for device with mac ${parsedEvent.mac}" - child.subscribe(parsedEvent.ip, parsedEvent.port) + if (child) { + log.debug "updating ip and port, and resubscribing, for device with mac ${parsedEvent.mac}" + child.subscribe(parsedEvent.ip, parsedEvent.port) + } else { + log.debug "Device with mac $parsedEvent.mac not found" + } } } } @@ -463,8 +471,12 @@ def locationHandler(evt) { deviceChangedValues = true log.debug "Device's port or ip changed..." def child = getChildDevice(parsedEvent.mac) - child.subscribe(parsedEvent.ip, parsedEvent.port) - child.poll() + if (child) { + child.subscribe(parsedEvent.ip, parsedEvent.port) + child.poll() + } else { + log.debug "Device with mac $parsedEvent.mac not found" + } } } } @@ -518,8 +530,12 @@ def locationHandler(evt) { deviceChangedValues = true log.debug "Device's port or ip changed..." def child = getChildDevice(parsedEvent.mac) - log.debug "updating ip and port, and resubscribing, for device with mac ${parsedEvent.mac}" - child.subscribe(parsedEvent.ip, parsedEvent.port) + if (child) { + log.debug "updating ip and port, and resubscribing, for device with mac ${parsedEvent.mac}" + child.subscribe(parsedEvent.ip, parsedEvent.port) + } else { + log.debug "Device with mac $parsedEvent.mac not found" + } } } }