I am losing my mind trying to figure this out, some maybe someone can shed some light on this for me please.
I have a SmartApp that I’m creating and the individual functions work as they are supposed to (custom created functions, etc.). I’ve even confirmed the SmartApp is installed on my mobile phone correctly.
I created a Device for what I’m working with, and I can see it has States (Door Control states of open and closed). This seems to be working properly as well.
HERE’S MY PROBLEM: I’m creating the Device Handler which will use the Door Control capability, and when I put in my own open(), close() opening() and closing() methods they look as though they work properly. HOWEVER, when I try to call a function built within the SmartApp (aka. parent.doSomething()), it fails with a response of:
error java.lang.NullPointerException: Cannot invoke method doSomething() on null object @line 123 (open)
I have my SmartApp and Device Handler both in the same namespaces, so looking over other examples of SmartApps and DH’s, I am assuming that I can use the object reference “parent.”, but apparently I’m mistaken.
Am I thinking of this wrong? Are SmartApp’s not considered a parent object to a Device Handler? If not, how can I reference the SmartApp methods or appSettings (aka variables) from within my Device Handler?
No (with the except of a SmartApp used that has spawned “child-devices”). Or is that what you’re specifically talking about???
Maybe that’s the problem I’m having. I’ve seen the videos on how to generate SmartApps, and I can make one work with the mobile app.
I can create a device and assign it to a Device Type (aka Device Hander), and I can create my own custom Device Handler with functions that [I assume] should call my specific SmartApp [within the same namespace] and execute methods within it.
As a programmer myself, not being able to reference the actual SmartApp from within the Device Handler, how is it supposed to communicate with the information within the SmartApp?
Again, am I thinking of this backwards? Is the parent the DH and the child is the SmartApp? I thought it was the otherway around…?
You know what, I decided to take the entire SmartApp out of the equation and just go with a Device and Device Handler, and being able to setup parameters within the DH, I don’t need the SmartApp for anything.
If the SmartApp creates the device, it should be addressable as the parent from the DTH. If it is created manually in the ide or setup though device discovery, there is no parent.
A SmartApp is required if 2 or more Devices interact.
SmartApps interface with Device instances based on the Commands and Attributes (set by Events) defined in the Device Type Handler.
Commands and Attributes are based on the specifications of the Capabilities claimed by the Device Type Handler. Switch Capability, for example, has Commands
on()/off()' and one Attribute switch= [on, off]`.
SmartApp detects Attribute changes by using the
subscribe() method. The sendEvent method for non-Attribute updates can be used in various circumstances by both SmartApps and Devices for rare special cases.
Thank you @TonyFleisher and @tgauchat for the input. I think I was having issues with understanding the separation of duties with a SmartApp and a Device Handler. I think for my use case, a DH and a Device was the only thing I needed for my task. I ended up completely deleting my device and dh and rebuilt, and now things are working properly within the mobile app; no smartapp needed.
I will consider this task as closed!
Thanks again guys!