Can my driver get a list of devices on the hub? i don't think so and thats ok

I asked Bing AI to show me how and it said to use device.getDevices(). No such luck, throws error: method not supported by device. Further searching seems to indicate this method is not available to user code. True?

I just wanted to find out if a user has already added a camera to their system using my driver so I know whether or not to tell them to rtfm first before they proceed. I do that with a message in the status attribute for the device that I set in the installed method. Silly I know, but thats me.

I just thought of something,,, local variables. I will just set one of those.

There are a couple of options here.... (EDIT - Which are not related to the OP at all.... :slight_smile: )

  • With HPM you could tell users to exclude your drivers / apps from automatic updates, if that is a concern (I believe this is an option....)
  • Something some dev's setup prior to HPM was to have their driver periodically poll their GitHub repo to check a "driver version" .json file to see if the local version on the HE hub matched the "available" version or not. The original dev for the EcoWitt drivers I now look after included this, which I have tweaked over the last little while....

True, AI lied to you.

If these are child devices (of a parent device or app), you can use methods in the parent to look for child devices however you want. If they are arbitrary devices on the user's system (including virtual/LAN devices the user may have added manually), the hub security model prevents you from doing that.

I don't see how any of these relate to the concern in the original post.

Yes, you are completely correct. Looking at it again I completely misread the OP, thinking it was about warning the user of the use of a driver before updating it, rather than simply to read the documentation.

Driver? No

App? Yes

This will get all the devices on you Hubitat with the capability of musicPlayer. Easy enough to adapt to what you’re doing. You can’t do web from drivers code, so you’ll need to make your driver a child driver from an app.

void getAllMusicPlayers() {
  Map params = [
    uri:"http://127.0.0.1:8080/device/listJson?capability=capability.musicPlayer",
    requestContentType: 'application/json',
    contentType: 'application/json',
    textParser: true
  ]
  logDebug(prettyJson(params))
  asynchttpGet('showMusic', params, null)
}

void showMusic(AsyncResponse response, Map data = null) {
  logDebug(response.getStatus())
  logDebug(response.getData())
}