Is there a way, within an app's "preferences" to get a list of all devices in com.hubitat.app.DeviceWrapper form?
I'm pretty sur e* I was able to do it with "allDevices" a.k.a., "getAllDevices()"
Maybe I'm having a mix-up on the function name?
What I"m trying to do is collect a list of all Switches that are not also Dimmers and present them to the user.
In the past, I'm pretty sure I could do it using code like I've shown below, but the "allDevices in line 20 seems to always return a null (and I've tried getAllDevices() which also returns null).
@thebearmay : I knew of that technique of getting the list via drop-down, but what I'm trying to do is to get the list without having to do it through the "input" selection process. I.e., get the list without user intereraction.
I'm looking for something like the getChildDevices() method that you use in a driver to returns a list of child device wrappers, but rather than getting "child" devices, I wanted to get All Devices in the system - i.e., all parents and all of their child devices.
Basically, what I want to do is . . .
Without user interaction, get the list of all devices as a List of
Filter it
And then use an "input" of type "enum" to present the filtered list, so the user can select from a pre-filtered list.
There's the really interesting approach @tony.fleisher does in his Z-Wave Mesh Details app. Under the "Grant access to z-wave devices" he has a check box to select all Z-Wave devices, which does an interesting dance to preselect the appropriate devices. It looks like it invokes an OAuth endpoint in his app which injects some JavaScript which seems to do a REST call to get all the device IDs and pre-select them.
I guess my secret is out. It works because javascript can do lots of fun things on the pages and since the browser has login context to the hub, the requests to the hub all have authorization as the user that is viewing the page. To use hub endpoints without on page javascript (assuming hub security is enabled), you have to have settings with authorization details first; @dman2306 used this approach with HPM.
As for getting the list of devices by capability, the best way I know of for this is the device listJson endpoint: /device/listJson?capability=capability.*
@mike.maxwell It would be really useful to expose the getDevices() method, I don't see the issue as long as the user could authorize the app as having special privilege.
e.g. I'd like to create an 'Associations' app which calls AssociationGroupingsGet when setup (on configure()) to check what associations exists on all devices... Then use the app to manage all associations. I'm thinking a virtual device could handle all lifeline events of a particular group in scenarios where the logging of events is required / event attributes are useful for more complex automation.
It's still a bit of a half-baked idea but without getDevices(), the wonkiness you have to through via JavaScript like @tony.fleisher just makes me put off this project continuously...
Our concern for wildcard methods like this within user apps being its potential use by bad actors as these methods don't require any user interaction to extract possibly sensitive data.