Code Snippit - External Driver and App Version Checking

Guys
As we have no GitHub integration yet, I have written some code to read an external JSON file, containing version numbers, and compare it to currently installed version.
This is then used to alert the user via the device page (and in the logs) that a new version is available.
It also gives you the ability to show a little update information as to what the new driver/app has

You can find the code here:

https://github.com/CobraVmax/Hubitat/tree/master/Update%20Code

There are two versions:

  1. Driver code
  2. App code

There is also an example JSON file in the same GitHub folder showing how to format the version numbers etc
You can host the JSON file on almost any website (or contact me and I'll host it for you and give you FTP access to it)

Driver Code
To use:
Add the code from GitHub to the bottom of your driver then add the method call: version() to the 'updated' section of your driver.
Four additional attributes also need to be added to your driver code (within the metadata section)

attribute "DriverAuthor", "string"
attribute "DriverVersion", "string"
attribute "DriverStatus", "string"
attribute "DriverUpdate", "string"

There are a couple of things to change in the code to make it work for you:

  1. The URI of the JSON code
  2. The 'Internal Name' (A name used in the JSON file to get the version)
  3. The driver's current version (so the code has something to compare the data from the JSON file with)
  4. The Cron expression - I use http://cronmaker.com to get those right.

This is what it looks like to the driver user when an update is available:

image

This is when everything is up to date:

image

By using 'NLS' (No Longer Supported) for the version number in the JSON file - This is what shows in the driver:

image

Application
To Use:

Add the code from GitHub to the bottom of your application.
Add the method call: version() to the 'updated' section of your app
Add the method call: display() to 'preferences' section where you want the version information displayed.

Again there are a couple of things to change in the code to make it work for you:

  1. The URI of the JSON code
  2. The 'Internal Name' (A name used in the JSON file to get the version)
  3. The app's current version (so the code has something to compare the data from the JSON file with)
  4. The Cron expression - I use http://cronmaker.com to get those right.

This is what it can look like when an update is available:

This is what it can look like when everything is up to date:

image

By using 'NLS' (No Longer Supported) for the version number in the JSON file - This is what shows in the app:

As this has taken me a while to refine, if you use this code in a driver or app I would really appreciate a 'credit' for my code somewhere
Also if you can find a better way to do this then please let me know :slight_smile:

Update 10/08/2018 - App code now available

Andy

7 Likes

Do you know if we can host the json file at git?

I host mine on one of my websites so have never tried.
I believe @csteele hosts his on his github account

Andy

I tested this the other day. Github works fine. I had to add the opening "{" for it to be processed as json though.

1 Like

Yes, you can.

You have to enable the Feature in github and then wait till the automation gets around to actually enabling.

  • First, prepare your versions.json. Then, on your github account create a new file and name it doc/versions.json

  • Paste in your contents and save it. (commit)

  • Then click the Settings Tab and scroll down to GitHub Pages. Set the Source to be Master Branch /doc and click save. Soon the site will tell you that the site is published at... and there ya go.

1 Like

Not a huge git user... What feature do I need to enable?
Thanks,
Craig

GitHub Pages <-- that feature.

do you have a github account? I can add you as a Member to HubitatCommunity, but I'll need to invite you using your github ID.

But I've put a recipe in the previous reply. :slight_smile:

yup,
Here is my hubitat repo

If you setup the GitHub Pages feature, you'll find your file at:

https://napalmscr.github.io/versions.json

Paste that into Cobra's code and you should be good to go.

Test by browsing to that URL first. Your browser should fetch the file and display it.

Invitation sent for HubitatCommunity.

You can use it in concert with your own github, if you wish. Your github becomes a lot like a Development repo, then you "publish" to HubitatCommunity.... least, that's what I do.

Thanks!
I joined, right now it says I should be good, here is to some testing!
Craig

Thanks for the help! Up and working.

1 Like