Is there a way to check if a Library is installed or not?

Would like to be able to check to see if a certain user Library is installed or not.

ie.

if(check for library) {
    libInstalled = true
} else {
    give a warning and a link to download...
}

Thanks.

@gopher.ny , @bravenel , etc. :wink:

1 Like

Backdoor would be to scrape http://yourHubIp:8080/library/list and search for the name. Could use the code from: [RELEASE] Web Scraper Device

3 Likes

Well, my solution for now is to try and call a method within the Library and trap on error.

libraryCheck()
if(state.libraryInstalled == 'COMPLETE') {
    ....
}
def libraryCheck(){
    try {
        checkForLibrary()    // only found within the Library
    } catch(e) {
        section("<b>Ooops!</b>") {
            paragraph "Library NOT found"
        }
    }
}
3 Likes

That will work. While you're doing it you may want to consider having it return a version number and check to make sure it satisfies your minimum version requirement.

4 Likes

Well, looks like my libraryCheck won't work after all. An app can't be saved that calls a library that doesn't exist. This is my last roadblock to be able to automatically download/update 'bundles' from GitHub.

Would need...

  • ability to save an app, even if a library called isn't present. Could throw an error in the log vs not being able to save.

Then I could trap it?

try{
#include BPTWorld.bpt-normalStuff
} catch(e) {
    magic happens...
}

@gopher.ny :wink:

I can add an app function that checks whether particular library (namespace/name) is installed.

4 Likes

Thanks, I look forward to seeing what you come up with.

Took a hard look at this too. In my case it still wouldn't work because we can't save an app if the #include doesn't exist. Thanks.

Will you please add this for use in drivers, too?

2 Likes

Download the Hubitat app